예제 #1
0
        public static void Delete(string fullName)
        {
            try
            {
                IEntry entry = FileFactory.CreateEntry(fullName);
                if (entry is MyZip)
                {
                    string pathToZip;
                    string pathInsideZip;

                    ParseZipPath(fullName, out pathToZip, out pathInsideZip);

                    MyZip zip = new MyZip(pathToZip);
                    zip.RemoveFromZip(pathInsideZip);
                }
                else if (Directory.Exists(fullName))
                {
                    Directory.Delete(fullName, true);
                }
                else
                {
                    File.Delete(fullName);
                }
            }
            catch (Exception e)
            {
                throw new MyException("Ошибка при удалении", e);
            }
        }
예제 #2
0
        public static void CreateFile(string path, byte[] content)
        {
            try
            {
                IEntry zip = FileFactory.CreateEntry(path);
                if (zip is MyZip)
                {
                    string pathToZip;
                    string pathInsideZip;
                    ParseZipPath(path, out pathToZip, out pathInsideZip);

                    MyZip _zip = new MyZip(pathToZip);
                    _zip.AddToZip(pathInsideZip, content);
                }
                else
                {
                    using (Stream outStream = File.Open(path, FileMode.Create))
                    {
                        outStream.Write(content, 0, content.Length);
                    }
                }
            }
            catch (Exception e)
            {
                throw new MyException("Ошибка при создании файла", e);
            }
        }
예제 #3
0
        public static void CreateDirectory(string path)
        {
            try
            {
                IEntry zIp = FileFactory.CreateEntry(path);
                if (zIp is MyZip)
                {
                    string pathToZip;
                    string pathInsideZip;

                    ParseZipPath(path, out pathToZip, out pathInsideZip);

                    MyZip zip = new MyZip(pathToZip);
                    zip.AddToZip(pathInsideZip, null);
                }
                else
                {
                    Directory.CreateDirectory(path);
                }
            }
            catch (Exception e)
            {
                throw new MyException("Ошибка при создании папки", e);
            }
        }
        // конструктор
        public ModelPresenter_Main(INavigation NavigationView, IMainAction ActionView)
        {
            this.navigationView   = NavigationView;
            this.ActionView       = ActionView;
            this.currentDirectory = FileFactory.CreateEntry("C:\\");

            NavigationView.MouseDoubleClick += new EventHandler <MainFormEventArgs>(OnMouseDoubleClick);


            ActionView.DeleteFile += new EventHandler <MainFormEventArgs>(OnFileDelete);
            ActionView.RenameFile += new EventHandler <MainFormEventArgs>(OnFileRename);
            ActionView.InsertFile += new EventHandler <MainFormEventArgs>(OnFileInsert);
            ActionView.CopyFile   += new EventHandler <MainFormEventArgs>(OnFileCopy);

            ActionView.FindInfoAwait    += new EventHandler <MainFormEventArgs>(OnFindInfoAwait);
            ActionView.FindInfoDelegate += new EventHandler <MainFormEventArgs>(OnFindInfoDelegate);
            ActionView.FindInfoParallel += new EventHandler <MainFormEventArgs>(OnFindInfoParallel);
            ActionView.FindInfoThread   += new EventHandler <MainFormEventArgs>(OnFindInfoThread);
            ActionView.allFindInfo      += new EventHandler <MainFormEventArgs>(OnZipFindInfo);

            ActionView.ArchiveAwait    += new EventHandler <MainFormEventArgs>(OnArchiveAwait);
            ActionView.ArchiveDelegate += new EventHandler <MainFormEventArgs>(OnArchiveDelegate);
            ActionView.ArchiveParallel += new EventHandler <MainFormEventArgs>(OnArchiveParallel);
            ActionView.ArchiveTask     += new EventHandler <MainFormEventArgs>(OnArchiveTask);
            ActionView.ArchiveThread   += new EventHandler <MainFormEventArgs>(OnArchiveThread);

            ActionView.PlinqStatistics += new EventHandler <MainFormEventArgs>(OnPlinqStatistics);
            OpenedDirectory(NavigationView.ICurrentDir);
        }
 public void OnMouseDoubleClick(object sender, MainFormEventArgs e)
 {
     if (e.Item.Contains(".sys"))
     {
     }
     if (e.Item != "..")
     {
         IEntry selectedEntry = FileFactory.CreateEntry(e.CurrentDir + @"\" + e.Item);
         if (selectedEntry is IDirectory)
         {
             currentDirectory = (IDirectory)selectedEntry;
             navigationView.RefreshCurrentDirectoryEntries();
         }
         else // if (selectedEntry is IFile)
         {
             Process.Start(selectedEntry.FullName);
         }
     }
     else
     {
         IEntry selectedEntry = FileFactory.CreateEntry(e.CurrentDir);
         if (selectedEntry is IDirectory)
         {
             currentDirectory = (IDirectory)selectedEntry;
             navigationView.RefreshCurrentDirectoryEntries();
         }
         else // if (selectedEntry is IFile)
         {
             Process.Start(selectedEntry.FullName);
         }
     }
     navigationView.OnDeleted = false;
 }
        public void OnFileRename(object sender, MainFormEventArgs e)
        {
            View.RenameDeleteForm rd = new View.RenameDeleteForm();
            if (rd.ShowDialog() == DialogResult.OK)
            {
                string newEntry = currentDirectory.FullName + @"\" + rd.txtBoxNewName.Text;
                IEntry oldEntry = FileFactory.CreateEntry(currentDirectory.FullName + @"\");
                if (oldEntry is IDirectory)
                {
                    InsertDirectory((IDirectory)oldEntry, newEntry);
                    MyDirectory.Delete(oldEntry.FullName);
                }
                else
                {
                    InsertFile((IFile)oldEntry, newEntry);
                    MyFile.Delete(oldEntry.FullName);
                }
                navigationView.RefreshCurrentDirectoryEntries();
            }



            /*       string target = e.CurrentDir + e.Item;
             *    if (MyDirectory.Exists(target))
             *         Directory.Move(target, e.CurrentDir + rd.txtBoxNewName.Text);
             *     else
             *         File.Move(target, e.CurrentDir + rd.txtBoxNewName.Text);
             *
             *     rd.Close();
             *     rd = null;
             *     OpenedDirectory(e.CurrentDir);
             *
             */
        }
        public void OnFileDelete(object sender, MainFormEventArgs e)
        {
            View.RenameDeleteForm rd = new View.RenameDeleteForm();
            rd.lblAreUSure.Visible   = true;
            rd.txtBoxNewName.Visible = false;
            rd.LblNewName.Visible    = false;
            rd.lblAreUSure.Font      = new Font("SanSerif", 12, FontStyle.Underline);

            if (rd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    IEntry entry = FileFactory.CreateEntry(e.CurrentDir + @"\" + e.Item);
                    if (entry is IDirectory)
                    {
                        MyDirectory.Delete(entry.FullName);
                    }
                    else
                    {
                        MyFile.Delete(entry.FullName);
                    }

                    navigationView.OnDeleted = true;
                    navigationView.RefreshCurrentDirectoryEntries_1();
                }
                catch (Exception ex)
                {
                    throw new MyException("Отказано в доступе", ex);
                }
            }
        }
예제 #8
0
        public void FindInfoInFile(string fileFullName)
        {
            IEntry file_to_open = FileFactory.CreateEntry(fileFullName);
            IFile  FILE         = (IFile)file_to_open;

            byte[] b = FILE.Open();
            // string f = System.Text.Encoding.UTF8.GetString(b);
            string f         = BytesToString(b, Encoding.Default);
            string curstring = f;


            // Сравниваем со всеми шаблонами по порядку
            for (int i = 0; i < regexes.Length; i++)
            {
                // В случае с пустым файлом, чтобы избежать ошибок, смотрим Matches не с curstring, а с ""
                // Если curstring == null

                Match m = regexes[i].Match(curstring == null ? "" : curstring);
                while (m.Value != "")
                {
                    data[i].Add(m.Value);
                    m = m.NextMatch();
                }
            }
        }
예제 #9
0
        //подпапки
        public ICollection <IEntry> GetItems()
        {
            List <IEntry> subItems = new List <IEntry>();

            IEntry fullname = FileFactory.CreateEntry(FullName);

            if (fullname is MyZip)
            {
                string outsideZip, insideZip;
                MyFileStream.ParseZipPath(FullName, out outsideZip, out insideZip);

                MyZip zip = new MyZip(outsideZip);
                foreach (IEntry entry in zip.GetAllItems())
                {
                    if (entry.FullName.Contains(Name + "/"))
                    {
                        subItems.Add(FileFactory.CreateEntry(entry.FullName.Replace('/', '\\')));
                    }
                }
            }
            else
            {
                foreach (IDirectory dir in dotNETDir.GetDirectories())
                {
                    subItems.Add(FileFactory.CreateEntry(dir.FullName));
                }
                foreach (IFile f in dotNETDir.GetFiles())
                {
                    subItems.Add(FileFactory.CreateEntry(f.FullName));
                }
            }
            return(subItems);
        }
예제 #10
0
        public void ArchiveFile(string sourceFile)
        {
            string destFile;
            bool   compress;
            IEntry _sourceFile = FileFactory.CreateEntry(sourceFile);

            // Определяемся с операцией архивирования/ обратной операции
            if (_sourceFile is MyZip)
            {
                destFile = Path.GetFileNameWithoutExtension(sourceFile);
                string temp = Path.GetExtension(destFile);
                destFile = Path.GetFileNameWithoutExtension(destFile);
                destFile = DirectiveName + destFile + "Unzipped" + temp;

                compress = false;
            }

            else
            {
                destFile = sourceFile + ".zip";
                compress = true;
            }

            const int BufferSize = 16384;

            byte[] buffer = new byte[BufferSize];

            try
            {
                using (Stream inFileStream = File.Open(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (Stream outFileStream = File.Open(destFile, FileMode.Create, FileAccess.Write, FileShare.None))
                        using (GZipStream gzipStream = new GZipStream(
                                   compress ? outFileStream : inFileStream,
                                   compress ? CompressionMode.Compress : CompressionMode.Decompress))
                        {
                            Stream inStream = compress ? inFileStream : gzipStream;
                            //compress true работаем со вторым файлом
                            //если false то с infile
                            Stream outStream = compress ? gzipStream : outFileStream;
                            int    bytesRead = 0;
                            do
                            {
                                bytesRead = inStream.Read(buffer, 0, BufferSize);
                                outStream.Write(buffer, 0, bytesRead);
                            }while (bytesRead > 0);
                        }
            }

            catch (UnauthorizedAccessException)
            {
                System.Windows.Forms.MessageBox.Show("Отказано в доступе!");
            }
            catch (Exception)
            {
                System.Windows.Forms.MessageBox.Show("Ошибка!");
            }
        }
예제 #11
0
        public void OnFileCopy(object sender, MainFormEventArgs e)
        {
            copySource      = FileFactory.CreateEntry(e.CurrentDir + @"\" + e.Item);
            copiedEntryName = "CopyOf" + MyFile.GetFileNameWithoutExtension(FileFactory.CreateEntry(e.CurrentDir + @"\" + e.Item).Name) +
                              MyFile.GetExtension(FileFactory.CreateEntry(e.CurrentDir + @"\" + e.Item).Name);

            /*Copied = e.CurrentDir + e.Item;
             * CopyName = "CopyOf" + e.Item;
             * OpenedDirectory(e.CurrentDir);*/
        }
예제 #12
0
        public void try_findinfo()
        {
            IEntry to_find_info_in_zip;

            if (SelectedIndex == -1)
            {
                to_find_info_in_zip = FileFactory.CreateEntry(CurrentDir);
            }
            else
            {
                to_find_info_in_zip = FileFactory.CreateEntry(CurrentDir + @"\" + SelectedItem);
            }
            // to_find_info_in_zip is IEntry
            GoDirs(to_find_info_in_zip);

            FindInfoInFile(file_reg_archive);

            //
            FileWrite(FileForRegex);
        }