53
53
public class ManageOMTPackage {
54
54
55
55
public static final String OMT_EXTENSION = ".omt" ;
56
- public static final String IGNORE_FILE = ".ignore " ;
56
+ public static final String IGNORE_FILE = ".empty " ;
57
57
static final ResourceBundle res = ResourceBundle .getBundle ("omt-package" , Locale .getDefault ());
58
58
private static JMenuItem importOMT ;
59
59
private static JMenuItem exportOMT ;
@@ -172,7 +172,7 @@ public static void projectExportOMT() {
172
172
.endsWith (OMT_EXTENSION ) ? ndm .getSelectedFile ()
173
173
: new File (ndm .getSelectedFile ().getAbsolutePath () + OMT_EXTENSION );
174
174
175
- Log .log (" \n \n ******* \n ******** \n " );
175
+ Log .log (String . format ( "Exporting OMT \" %s \" " , omtFile . getAbsolutePath ()) );
176
176
177
177
// Check and ask if the user wants to overwrite an existing package
178
178
if (omtFile .exists ()) {
@@ -314,7 +314,7 @@ public static void createOmt(final File omtZip, final ProjectProperties props) t
314
314
}
315
315
316
316
BufferedOutputStream bos = new BufferedOutputStream (new FileOutputStream (omtZip ));
317
-
317
+ Log . log ( String . format ( "Zipping to file [%s]" , omtZip . getAbsolutePath ()));
318
318
try (ZipOutputStream out = new ZipOutputStream (bos )) {
319
319
addZipDir (out , null , path , props );
320
320
}
@@ -334,24 +334,39 @@ private static final void addZipDir(final ZipOutputStream out, final Path root,
334
334
final Path childPath = child .getFileName ();
335
335
336
336
final String name = childPath .toFile ().getName ();
337
- if (name .endsWith (OConsts .BACKUP_EXTENSION ) || name .endsWith (OMT_EXTENSION )
337
+
338
+ // TODO - The list of excluded/included files should be read from a
339
+ // properties file in OmT config folder.
340
+ if (name .endsWith (".zip" ) || name .endsWith (OConsts .BACKUP_EXTENSION ) || name .endsWith (OMT_EXTENSION )
338
341
) {
339
342
// Skip .bak and .omt files
340
343
continue ;
341
344
}
342
- if (childPath .endsWith (OConsts .FILE_PROJECT )) {
345
+
346
+ // Skip projects inside projects
347
+ if (Files .isDirectory (child ) && new File (child .toFile (), OConsts .FILE_PROJECT ).exists ()) {
348
+ Log .log (String .format ("The directory \" %s\" appears to be an OmegaT project, we'll skip it." , child .toFile ().getAbsolutePath ()));
349
+ continue ;
350
+ }
351
+
352
+ if (root == null && childPath .endsWith (OConsts .FILE_PROJECT )) {
343
353
// Special case - when a project is opened, the project file is locked and
344
354
// can't be copied directly. To avoid this, we make a temp copy.
345
- File tmpProjectFile = File .createTempFile ("omt" , null , props .getProjectRootDir ());
355
+ // We name it with a .bak extension to make sure it's not included in the package.
356
+ File tmpProjectFile = File .createTempFile ("omt" , OConsts .BACKUP_EXTENSION , props .getProjectRootDir ());
346
357
try {
347
358
ProjectFileStorage .writeProjectFile (props , tmpProjectFile );
348
359
} catch (Exception e ) {
349
360
throw new IOException (e );
350
361
}
362
+ Log .log (String .format ("addZipDir\t project\t [%s]" , OConsts .FILE_PROJECT ));
351
363
out .putNextEntry (new ZipEntry (OConsts .FILE_PROJECT ));
352
364
Files .copy (Paths .get (tmpProjectFile .getAbsolutePath ()), out );
353
365
out .closeEntry ();
354
- tmpProjectFile .delete ();
366
+ boolean isTmpDeleted = tmpProjectFile .delete ();
367
+ if (!isTmpDeleted ) {
368
+ Log .log (String .format ("Could not delete temporary file \" %s\" . You can safely delete it." , tmpProjectFile .getAbsolutePath ()));
369
+ }
355
370
continue ;
356
371
}
357
372
@@ -360,11 +375,14 @@ private static final void addZipDir(final ZipOutputStream out, final Path root,
360
375
// Before recursing, we add a ZipEntry for the directory to allow
361
376
// empty dirs.
362
377
if (child .toFile ().listFiles ().length == 0 ) {
363
- out .putNextEntry (new ZipEntry (name + File .separatorChar + IGNORE_FILE ));
378
+ String emptyDirFile = entry .toString () + File .separatorChar + IGNORE_FILE ;
379
+ Log .log (String .format ("addZipDir\t empty\t [%s]" , emptyDirFile ));
380
+ out .putNextEntry (new ZipEntry (emptyDirFile ));
364
381
out .closeEntry ();
365
382
}
366
383
addZipDir (out , entry , child , props );
367
384
} else {
385
+ Log .log (String .format ("addZipDir\t file\t [%s]" , entry ));
368
386
out .putNextEntry (new ZipEntry (entry .toString ()));
369
387
Files .copy (child , out );
370
388
out .closeEntry ();
0 commit comments