Lines 43-48
Link Here
|
43 |
|
43 |
|
44 |
import java.io.File; |
44 |
import java.io.File; |
45 |
import java.io.FileInputStream; |
45 |
import java.io.FileInputStream; |
|
|
46 |
import java.io.FileNotFoundException; |
46 |
import java.io.FileOutputStream; |
47 |
import java.io.FileOutputStream; |
47 |
import java.io.IOException; |
48 |
import java.io.IOException; |
48 |
import java.io.InputStream; |
49 |
import java.io.InputStream; |
Lines 175-219
Link Here
|
175 |
void doImport(File targetUserdir) throws IOException { |
176 |
void doImport(File targetUserdir) throws IOException { |
176 |
LOGGER.fine("Copying from: " + source + "\n to: " + targetUserdir); //NOI18N |
177 |
LOGGER.fine("Copying from: " + source + "\n to: " + targetUserdir); //NOI18N |
177 |
this.targetUserdir = targetUserdir; |
178 |
this.targetUserdir = targetUserdir; |
178 |
FileUtil.getConfigRoot().addRecursiveListener(new FileChangeListener() { |
|
|
179 |
|
180 |
@Override |
181 |
public void fileFolderCreated(FileEvent fe) { |
182 |
String path = fe.getFile().getPath(); |
183 |
Preferences pref = Preferences.userRoot().node(path); |
184 |
} |
185 |
|
186 |
@Override |
187 |
public void fileDataCreated(FileEvent fe) { |
188 |
String path = fe.getFile().getPath(); |
189 |
Preferences pref = NbPreferences.root().node("config").node(path); |
190 |
} |
191 |
|
192 |
@Override |
193 |
public void fileChanged(FileEvent fe) { |
194 |
String path = fe.getFile().getPath(); |
195 |
Preferences pref = NbPreferences.root().node("config").node(path); |
196 |
} |
197 |
|
198 |
@Override |
199 |
public void fileDeleted(FileEvent fe) { |
200 |
String path = fe.getFile().getPath(); |
201 |
Preferences pref = NbPreferences.root().node("config").node(path); |
202 |
try { |
203 |
pref.removeNode(); |
204 |
} catch (BackingStoreException ex) { |
205 |
Exceptions.printStackTrace(ex); |
206 |
} |
207 |
} |
208 |
|
209 |
@Override |
210 |
public void fileRenamed(FileRenameEvent fe) { |
211 |
} |
212 |
|
213 |
@Override |
214 |
public void fileAttributeChanged(FileAttributeEvent fe) { |
215 |
} |
216 |
}); |
217 |
copyFiles(); |
179 |
copyFiles(); |
218 |
} |
180 |
} |
219 |
|
181 |
|
Lines 225-231
Link Here
|
225 |
try { |
187 |
try { |
226 |
ensureParent(targetZipFile); |
188 |
ensureParent(targetZipFile); |
227 |
// Create the ZIP file |
189 |
// Create the ZIP file |
228 |
zipOutputStream = new ZipOutputStream(new FileOutputStream(targetZipFile)); |
190 |
zipOutputStream = new ZipOutputStream(createOutputStream(targetZipFile)); |
229 |
copyFiles(); |
191 |
copyFiles(); |
230 |
createProductInfo(zipOutputStream); |
192 |
createProductInfo(zipOutputStream); |
231 |
// Complete the ZIP file |
193 |
// Complete the ZIP file |
Lines 869-875
Link Here
|
869 |
if (includeKeys.isEmpty() && excludeKeys.isEmpty()) { |
831 |
if (includeKeys.isEmpty() && excludeKeys.isEmpty()) { |
870 |
// copy entire file |
832 |
// copy entire file |
871 |
try { |
833 |
try { |
872 |
out = new FileOutputStream(targetFile); |
834 |
out = createOutputStream(targetFile); |
873 |
copyFile(relativePath, out); |
835 |
copyFile(relativePath, out); |
874 |
} finally { |
836 |
} finally { |
875 |
if (out != null) { |
837 |
if (out != null) { |
Lines 915-921
Link Here
|
915 |
} |
877 |
} |
916 |
OutputStream out = null; |
878 |
OutputStream out = null; |
917 |
try { |
879 |
try { |
918 |
out = new FileOutputStream(targetFile); |
880 |
out = createOutputStream(targetFile); |
919 |
targetProperties.store(out); |
881 |
targetProperties.store(out); |
920 |
} finally { |
882 |
} finally { |
921 |
if (out != null) { |
883 |
if (out != null) { |
Lines 1041-1047
Link Here
|
1041 |
ZipOutputStream out = null; |
1003 |
ZipOutputStream out = null; |
1042 |
try { |
1004 |
try { |
1043 |
// Create the ZIP file |
1005 |
// Create the ZIP file |
1044 |
out = new ZipOutputStream(new FileOutputStream(targetFile)); |
1006 |
out = new ZipOutputStream(createOutputStream(targetFile)); |
1045 |
// Compress the files |
1007 |
// Compress the files |
1046 |
for (String relativePath : relativePaths) { |
1008 |
for (String relativePath : relativePaths) { |
1047 |
LOGGER.finest("Adding to zip: " + relativePath); //NOI18N |
1009 |
LOGGER.finest("Adding to zip: " + relativePath); //NOI18N |
Lines 1091-1094
Link Here
|
1091 |
// Complete the entry |
1053 |
// Complete the entry |
1092 |
out.closeEntry(); |
1054 |
out.closeEntry(); |
1093 |
} |
1055 |
} |
|
|
1056 |
|
1057 |
private static OutputStream createOutputStream(File file) throws IOException { |
1058 |
if (containsConfig(file)) { |
1059 |
file = file.getCanonicalFile(); |
1060 |
File root = FileUtil.toFile(FileUtil.getConfigRoot()); |
1061 |
String filePath = file.getPath(); |
1062 |
String rootPath = root.getPath(); |
1063 |
if (filePath.startsWith(rootPath)) { |
1064 |
String res = filePath.substring(rootPath.length()).replace(File.separatorChar, '/'); |
1065 |
FileObject fo = FileUtil.createData(FileUtil.getConfigRoot(), res); |
1066 |
if (fo != null) { |
1067 |
return fo.getOutputStream(); |
1068 |
} |
1069 |
} |
1070 |
} |
1071 |
return new FileOutputStream(file); |
1072 |
} |
1073 |
private static boolean containsConfig(File file) { |
1074 |
for (;;) { |
1075 |
if (file == null) { |
1076 |
return false; |
1077 |
} |
1078 |
if (file.getName().equals("config")) { |
1079 |
return true; |
1080 |
} |
1081 |
file = file.getParentFile(); |
1082 |
} |
1083 |
} |
1094 |
} |
1084 |
} |