Exemplo n.º 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);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /* public void FindInformation()
         * {
         *   IEntry to_find_info_in = FileSystemFactory.CreateEntry(CurrentDir + @"\" + SelectedItem);
         *   if (to_find_info_in is IDirectory)
         *   {
         *       GoDirs((IDirectory)to_find_info_in);
         *   }
         *   /*IDirectory cd;
         *   if (SelectedIndex == -1)
         *   {
         *       cd = new IDirectory(CurrentDir);
         *   }
         *
         *
         *   else
         *   {
         *       cd = new IDirectory(CurrentDir + SelectedItem.ToString());
         *   }
         */

        // Пробег по папкам и сбор имен всех файлов
        // Как итог имеем Лист полный названий всяких файлов

        // GoDirs(cd);
        // имя -> dirinfo + GoDirs();*/
        public void GoZIP(MyZip currentDir)
        {
            file_reg_archive.Add(currentDir.FullName);
        }