Revision 1855

tmp/org.txm.rcp/src/main/java/org/txm/rcp/ApplicationWorkbenchAdvisor.java (revision 1855)
759 759
		return true;
760 760
	}
761 761

  
762
	private void createBackUpDirectory(IProgressMonitor monitor) {
763

  
764
		backup = new File(txmhomedir, "corpus-backup"); //$NON-NLS-1$
765
		oldbackup = new File(txmhomedir, "corpus-backup-old"); //$NON-NLS-1$
766
		errorbackup = new File(txmhomedir, "corpus-backup-error"); //$NON-NLS-1$
767

  
768
		corporaDir = new File(txmhomedir, "corpora"); //$NON-NLS-1$
769

  
770
		File[] corporaDirFiles = corporaDir.listFiles(IOUtils.HIDDENFILE_FILTER);
771
		if (corporaDir.exists() && corporaDirFiles != null && corporaDirFiles.length > 0) { // if the txmhomedir is not empty, try to restore its content
772
			Display.getDefault().syncExec(new Runnable() {
773
				@Override
774
				public void run() {
775
					Display display = Display.getDefault();
776
					Shell shell = display.getActiveShell();
777
					go = MessageDialog.openConfirm(shell, TXMUIMessages.workspaceDirectoryBackup, NLS.bind(TXMUIMessages.tXMWorkspaceDirectoryAlreadyExistsP0WouldYouLikeToReloadItsCorporaInYourNewTXM, txmhomedir));
778
				}
779
			});
780

  
781
			if (go) {
782
				monitor.setTaskName(TXMUIMessages.bind(TXMUIMessages.movingCorporaToP0, backup.getAbsolutePath()));
783
				backup.mkdir();
784

  
785
				if (!backup.exists()) {
786
					System.out.println(TXMCoreMessages.bind(TXMUIMessages.couldNotCreateBackupDirectoryColon, backup));
787
					return;
788
				}
789

  
790
				//$NON-NLS-1$
791
				if (oldbackup.exists()) {
792
					Log.info(TXMUIMessages.bind(TXMUIMessages.removingOldCorpusBackupDirectoryP0, oldbackup));
793
					DeleteDir.deleteDirectory(oldbackup); // ]8)
794
				}
795

  
796
				File[] corpDirs = corporaDir.listFiles(IOUtils.HIDDENFILE_FILTER);
797
				ArrayList<String> moved = new ArrayList<String>();
798
				ArrayList<String> failed = new ArrayList<String>();
799

  
800
				if (corpDirs != null) {
801
					Arrays.sort(corpDirs);
802
					System.out.print(TXMUIMessages.bind(TXMUIMessages.movingCorporaToP0, backup.getAbsolutePath()));
803
					for (File corpusdir : corpDirs) {
804
						File backCorpus = new File(backup, corpusdir.getName());
805
						if (corpusdir.canRead() && corpusdir.isDirectory()) {
806
							System.out.print("."); //$NON-NLS-1$
807
							if (backCorpus.exists()) {
808
								moved.add(corpusdir.getName());
809
								oldbackup.mkdir();
810
								backCorpus.renameTo(new File(oldbackup, corpusdir.getName()));
811
							}
812

  
813
							if (!corpusdir.renameTo(backCorpus)) {
814
								failed.add(corpusdir.getName());
815
							}
816
						}
817
					}
818
					System.out.println();
819
				}
820
				if (moved.size() > 0) {
821
					Log.info(TXMCoreMessages.bind(TXMUIMessages.corporaBackupedColonP0, oldbackup, StringUtils.join(moved, ", "))); //$NON-NLS-1$
822
				}
823
				if (failed.size() > 0) {
824
					System.out.println(TXMCoreMessages.bind(TXMUIMessages.failedToMoveCorpus, failed, backup));
825
				}
826
			}
827
		}
828
	}
829

  
830 762
	/**
831 763
	 * Install the sample corpora and previous TXM version corpora in TXM corpora directory
832 764
	 * @param monitor
......
880 812
			}
881 813
		});
882 814
		
815
		// move previous TXM 0.8.0 corpora
816
		File backupDir = new File(corporaDir.getAbsolutePath()+"-previous");
817
		if (corporaDir.exists()) {
818
			backupDir.mkdirs();
819
			for (File dir : corporaDir.listFiles(IOUtils.HIDDENFILE_FILTER)) {
820
				File bdir = new File(backupDir, dir.getName());
821
				DeleteDir.deleteDirectory(bdir);
822
				dir.renameTo(bdir);
823
			}
824
		}
825
		
883 826
		// load TXM-0.8.0 sample corpora (from the install directory)
884 827
				if (corporaDirs.contains(SAMPLES) && sampleCorporaDirectory.exists()) {
885 828

  
......
895 838
				}
896 839
		
897 840
		// TXM-0.8.0 previous installation corpora
898
		if (corporaDirs.contains(V080) && corporaDir.listFiles(IOUtils.HIDDENFILE_FILTER).length > 0) { // not a new install, restore previous corpora
841
		if (corporaDirs.contains(V080) && backupDir.listFiles(IOUtils.HIDDENFILE_FILTER).length > 0) { // not a new install, restore corpus from the corpora-previous directory
899 842
			Log.info(NLS.bind(TXMUIMessages.installingPreviousCorpusFromP0, "0.8.0", corporaDir));
900
			JobHandler job = LoadBinaryCorporaDirectory.loadBinaryCorpusFromCorporaDirectory(corporaDir, false, false, true);
843
			JobHandler job = LoadBinaryCorporaDirectory.loadBinaryCorpusFromCorporaDirectory(backupDir, false, false, true);
901 844
			try {
902 845
				job.join();
903 846
			} catch (InterruptedException e) {
904 847
				e.printStackTrace();
905 848
			}
906
		} else if (corporaDir.exists()) {
907
			File backupDir = new File(corporaDir.getAbsolutePath()+"-previous");
908
			backupDir.mkdirs();
909
			for (File dir : corporaDir.listFiles(IOUtils.HIDDENFILE_FILTER)) {
910
				File bdir = new File(backupDir, dir.getName());
911
				DeleteDir.deleteDirectory(bdir);
912
				dir.renameTo(bdir);
913
			}
914 849
		}
915 850
		
916 851
		// TXM previous installation corpora

Also available in: Unified diff