コード例 #1
0
 public void openLocalFolder() {
   try {
     File localFolder = settings.getLocalFolder();
     Desktop.getDesktop().open(localFolder);
   } catch (IOException ex) {
     model.addErrorMessage("Verzeichnis konnte nicht geöffnet werden");
   }
 }
コード例 #2
0
 public void changeLocalFolder(File folder) {
   try {
     File oldFolder = settings.getLocalFolder();
     Files.move(oldFolder.toPath(), folder.toPath(), StandardCopyOption.REPLACE_EXISTING);
     settings.setLocalFolder(folder);
   } catch (IOException ex) {
     model.addErrorMessage("Verzeichnis konnte nicht geändert werden");
   }
   model.fireChange();
 }
コード例 #3
0
 private Logfile createLogfile() {
   File folder = new File(settings.getLocalFolder(), "logs");
   DateFormat format = new SimpleDateFormat("dd_mm_yyyy");
   Date date = new Date();
   String folderName = format.format(date);
   File logFileFolder = new File(folder, folderName);
   if (!logFileFolder.exists()) {
     logFileFolder.mkdirs();
   }
   int numFiles = logFileFolder.listFiles().length;
   File file = new File(logFileFolder, "log_" + numFiles + ".txt");
   Logfile logfile = new Logfile(file);
   return logfile;
 }
コード例 #4
0
 private void saveServers() {
   File serverDir = new File(settings.getLocalFolder(), "servers");
   if (!serverDir.exists()) {
     serverDir.mkdirs();
   }
   for (Server s : model.getAllServers()) {
     try {
       File serverFile = new File(serverDir, s.getName() + ".server");
       s.writeToFile(serverFile);
     } catch (IOException ex) {
       logger.log(Level.SEVERE, null, ex);
     }
   }
 }
コード例 #5
0
 public void deleteKnownServer() {
   Server currentServer = model.getCurrentServer();
   if (currentServer != null) {
     try {
       model.removeServer(currentServer);
       File serverDir = new File(settings.getLocalFolder(), "servers");
       File serverFile = new File(serverDir, currentServer.getName() + ".server");
       Files.delete(serverFile.toPath());
     } catch (IOException ex) {
       model.addErrorMessage("Server-Datei konnte nicht gelöscht werden");
       logger.log(Level.SEVERE, null, ex);
     }
     model.fireChange();
   }
 }
コード例 #6
0
 public void loadServers() {
   File serverDir = new File(settings.getLocalFolder(), "servers");
   if (serverDir.exists()) {
     for (File f : serverDir.listFiles()) {
       ObjectInputStream oIn = null;
       try {
         oIn = new ObjectInputStream(new FileInputStream(f));
         Server server = (Server) oIn.readObject();
         model.addServer(server);
         oIn.close();
       } catch (IOException | ClassNotFoundException ex) {
         logger.log(Level.SEVERE, null, ex);
       } finally {
         try {
           oIn.close();
         } catch (IOException ex) {
           logger.log(Level.SEVERE, null, ex);
         }
       }
     }
     model.fireChange();
   }
 }