コード例 #1
0
 private void OnRenamed(object source, FileSystemEventArgs e)
 {
     try
     {
         FileAttributes attributes = File.GetAttributes(e.FullPath);
         if ((attributes & FileAttributes.Directory) != FileAttributes.Directory)
         {
             //this is not a save file to backup save file event
             var renamedEvent = (RenamedEventArgs)e;
             if (!renamedEvent.Name.Contains("Backup"))
             {
                 FileReadyEvent fileReadyEvent = null;
                 if (m_Timers.ContainsKey(e.FullPath))
                 {
                     fileReadyEvent = m_Timers[e.FullPath];
                     fileReadyEvent.Stop();
                 }
                 else
                 {
                     fileReadyEvent        = new FileReadyEvent(e.FullPath, new TimeSpan(0, 0, 5), m_MainDispatcher);
                     fileReadyEvent.Ready += new EventHandler <FileReadyEvent.StringEventArgs>(OnFileReady);
                     m_Timers.Add(e.FullPath, fileReadyEvent);
                 }
                 fileReadyEvent.Start();
             }
         }
     }
     catch (System.Exception)
     {
         //couldnt get attributes for file so just let it pass
     }
 }
コード例 #2
0
 private void OnChanged(object source, FileSystemEventArgs e)
 {
     try
     {
         FileAttributes attributes = File.GetAttributes(e.FullPath);
         if ((attributes & FileAttributes.Directory) != FileAttributes.Directory)
         {
             if (!e.FullPath.EndsWith(".tmp"))
             {
                 FileReadyEvent fileReadyEvent = null;
                 if (m_Timers.ContainsKey(e.FullPath))
                 {
                     fileReadyEvent = m_Timers[e.FullPath];
                     fileReadyEvent.Stop();
                 }
                 else
                 {
                     fileReadyEvent        = new FileReadyEvent(e.FullPath, new TimeSpan(0, 0, 5), m_MainDispatcher);
                     fileReadyEvent.Ready += new EventHandler <FileReadyEvent.StringEventArgs>(OnFileReady);
                     m_Timers.Add(e.FullPath, fileReadyEvent);
                 }
                 fileReadyEvent.Start();
             }
         }
     }
     catch (System.Exception)
     {
         //couldnt get attributes for file so just let it pass
     }
 }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: rselbo/SaveScummer
 private void OnChanged(object source, FileSystemEventArgs e)
 {
   try
   {
     FileAttributes attributes = File.GetAttributes(e.FullPath);
     if ((attributes & FileAttributes.Directory) != FileAttributes.Directory)
     {
       FileReadyEvent fileReadyEvent = null;
       if(m_Timers.ContainsKey(e.FullPath))
       {
         fileReadyEvent = m_Timers[e.FullPath];
         fileReadyEvent.Stop();
       }
       else
       {
         fileReadyEvent = new FileReadyEvent(e.FullPath, new TimeSpan(0, 0, 5), m_MainDispatcher);
         fileReadyEvent.Ready += new EventHandler<FileReadyEvent.StringEventArgs>(OnFileReady);
         m_Timers.Add(e.FullPath, fileReadyEvent);
       }
       fileReadyEvent.Start();        
     }
   }
   catch (System.Exception)
   {
     //couldnt get attributes for file so just let it pass
   }
 }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: rselbo/SaveScummer
    private void OnFileReady(object source, FileReadyEvent.StringEventArgs e)
    {
      m_Timers.Remove(e.Data);
      // Specify what is done when a file is changed, created, or deleted.
      String fullPath = e.Data;
      String path = e.Data;
      if (path.StartsWith(m_SaveScumFolder))
      {
        path = path.Substring(m_SaveScumFolder.Length).TrimStart('\\');
      }

      String dir = System.IO.Path.GetDirectoryName(path);
      String filename = System.IO.Path.GetFileNameWithoutExtension(path);
      String extension = System.IO.Path.GetExtension(path);

      String backupPath = System.IO.Path.Combine(dir, filename + DateTime.Now.ToString(".yyyyMMddHHmmss") + extension);
      String fullBackupPath = System.IO.Path.Combine(SaveScumBackupFolder, backupPath);

      BackupLog += "Backing up " + e.Data + " to " + backupPath + "\n";
      Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fullBackupPath));
      File.Copy(fullPath, fullBackupPath);
      BackupLog += "done\n";
    }