예제 #1
0
 public EFESFSFile(SFSFile File)
 {
     this.File = File;
     this.Parent = Parent;
     if (Parent != null) Parent.Children.Add(this);
     Name = File.FileName;
     PrepareDataForUse(File.Data);
 }
 public EFESFSFile(SFSFile File)
 {
     this.File   = File;
     this.Parent = Parent;
     if (Parent != null)
     {
         Parent.Children.Add(this);
     }
     Name = File.FileName;
     PrepareDataForUse(File.Data);
 }
 public SFSFile GetFileByID(int Id)
 {
     foreach (SFSFile f in Files)
     {
         if (f.FileID == Id)
         {
             return(f);
         }
     }
     foreach (SFSDirectory d in SubDirectories)
     {
         SFSFile f = d.GetFileByID(Id);
         if (f != null)
         {
             return(f);
         }
     }
     return(null);
 }
예제 #4
0
 private void fileBrowser1_OnAddFile(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
         && openFileDialog1.FileName.Length > 0)
     {
         var dir = Root.GetDirectoryByPath(fileBrowser1.SelectedFolderPath);
         if (!dir.IsValidName(System.IO.Path.GetFileName(openFileDialog1.FileName)))
         {
             switch (MessageBox.Show("A file with the same name as the selected file exists. Do you want to replace this file?", "Replace", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
             {
                 case System.Windows.Forms.DialogResult.Yes:
                     var file = Root.GetFileByPath(fileBrowser1.SelectedFolderPath + "/" + System.IO.Path.GetFileName(openFileDialog1.FileName));
                     file.Data = System.IO.File.ReadAllBytes(openFileDialog1.FileName);
                     break;
                 case System.Windows.Forms.DialogResult.No:
                     int nr = 0;
                     String NewName;
                     do
                     {
                         NewName = System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName) + "_" + nr++ + System.IO.Path.GetExtension(openFileDialog1.FileName);
                     }
                     while (!dir.IsValidName(NewName));
                     SFSFile f = new SFSFile(-1, NewName, dir);
                     f.Data = System.IO.File.ReadAllBytes(openFileDialog1.FileName);
                     dir.Files.Add(f);
                     break;
             }
         }
         else
         {
             SFSFile f = new SFSFile(-1, System.IO.Path.GetFileName(openFileDialog1.FileName), dir);
             f.Data = System.IO.File.ReadAllBytes(openFileDialog1.FileName);
             dir.Files.Add(f);
         }
         Archive.FromFileSystem(Root);
         fileBrowser1.UpdateDirectories(Root.GetTreeNodes(), true);
     }
 }