Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / PackFile.java @ 15280

History | View | Annotate | Download (5.25 KB)

1
/*
2
 *  $Id: PackFile.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
3
 *  IzPack
4
 *  Copyright (C) 2001 Johannes Lehtinen
5
 *
6
 *  File :               Pack.java
7
 *  Description :        Contains informations about a pack file.
8
 *  Author's email :     johannes.lehtinen@iki.fi
9
 *  Author's Website :   http://www.iki.fi/jle/
10
 *
11
 *  This program is free software; you can redistribute it and/or
12
 *  modify it under the terms of the GNU General Public License
13
 *  as published by the Free Software Foundation; either version 2
14
 *  of the License, or any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU General Public License
22
 *  along with this program; if not, write to the Free Software
23
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24
 */
25
package com.izforge.izpack;
26

    
27
import java.io.File;
28
import java.io.FileNotFoundException;
29
import java.io.Serializable;
30
import java.util.List;
31
import java.util.Map;
32

    
33
/**
34
 *  Encloses information about a packed file. This class abstracts the way file
35
 *  data is stored to package.
36
 *
37
 * @author     Johannes Lehtinen <johannes.lehtinen@iki.fi>
38
 */
39
public class PackFile implements Serializable
40
{
41
  public static final int OVERRIDE_FALSE = 0;
42
  public static final int OVERRIDE_TRUE = 1;
43
  public static final int OVERRIDE_ASK_FALSE = 2;
44
  public static final int OVERRIDE_ASK_TRUE = 3;
45
  public static final int OVERRIDE_UPDATE = 4;
46

    
47
  public String sourcePath = null;
48

    
49
  /**  The full path name of the target file */
50
  private String targetPath = null;
51

    
52
  /**  The target operating system constraints of this file */
53
  private List osConstraints = null;
54

    
55
  /**  The length of the file in bytes */
56
  private long length = 0;
57

    
58
  /**  The last-modification time of the file. */
59
  private long mtime = -1;
60

    
61
  /** True if file is a directory (length should be 0 or ignored) */
62
  private boolean isDirectory = false;
63

    
64
  /**  Whether or not this file is going to override any existing ones */
65
  private int override = OVERRIDE_FALSE;
66

    
67
  /** Additional attributes or any else for customisation */
68
  private Map  additionals = null;
69

    
70

    
71
  public int previousPackNumber = -1;
72
  public long offsetInPreviousPack = -1;
73
  
74
  /**
75
   * Constructs and initializes from a source file.
76
   *
77
   * @param  src      file which this PackFile describes
78
   * @param  target   the path to install the file to
79
   * @param  osList   OS constraints
80
   * @param  override what to do when the file already exists
81
   * @throws FileNotFoundException if the specified file does not exist.
82
   */
83
  public PackFile(File src, String target, List osList, int override)
84
    throws FileNotFoundException
85
  {
86
    if (! src.exists()) // allows cleaner client co
87
      throw new FileNotFoundException("No such file: "+src);
88
    
89
    if ('/' != File.separatorChar)
90
      target = target.replace(File.separatorChar, '/');
91
    if (target.endsWith("/"))
92
      target = target.substring(0, target.length()-1);
93

    
94
    this.sourcePath = src.getPath();
95
    this.targetPath = target;
96
    this.osConstraints = osList;
97
    this.override = override;
98

    
99
    this.length = src.length();
100
    this.mtime = src.lastModified();
101
    this.isDirectory = src.isDirectory();
102
  }
103

    
104
  /**
105
   * Constructs and initializes from a source file.
106
   *
107
   * @param  src      file which this PackFile describes
108
   * @param  target   the path to install the file to
109
   * @param  osList   OS constraints
110
   * @param  override what to do when the file already exists
111
   * @param  additionals  additional attributes
112
   * @throws FileNotFoundException if the specified file does not exist.
113
   */
114
  public PackFile(File src, String target, List osList, int override,
115
    Map additionals) throws FileNotFoundException
116
  {
117
    this( src, target, osList, override);
118
    this.additionals = additionals;
119
  }
120

    
121
  public void setPreviousPackFileRef(int previousPackNumber,
122
                                     long offsetInPreviousPack)
123
  {
124
    this.previousPackNumber = previousPackNumber;
125
    this.offsetInPreviousPack = offsetInPreviousPack;
126
  }
127

    
128
  /**  The target operating system constraints of this file */
129
  public final List osConstraints()
130
  {
131
    return osConstraints;
132
  }
133

    
134
  /**  The length of the file in bytes */
135
  public final long length()
136
  {
137
    return length;
138
  }
139

    
140
  /**  The last-modification time of the file. */
141
  public final long lastModified()
142
  {
143
    return mtime;
144
  }
145

    
146
  /**  Whether or not this file is going to override any existing ones */
147
  public final int override()
148
  {
149
    return override;
150
  }
151

    
152
  public final boolean isDirectory()
153
  {
154
    return isDirectory;
155
  }
156

    
157
  public final boolean isBackReference()
158
  {
159
    return (previousPackNumber >= 0);
160
  }
161

    
162
  /**  The full path name of the target file, using '/' as fileseparator. */
163
  public final String getTargetPath()
164
  {
165
    return targetPath;
166
  }
167
  /**
168
   * Returns the additionals map.
169
   * @return additionals
170
   */
171
  public Map getAdditionals()
172
  {
173
    return additionals;
174
  }
175

    
176
}