Пример #1
0
        public Form1()
        {
            InitializeComponent();
            drivers = EntityFunctions.GetDrivers();

            foreach (var disc in drivers)
            {
                listBoxOfDisks.Items.Add(disc);
            }

            fontDialog1.ShowColor = true;

            listBoxOfDisks.DoubleClick  += new EventHandler(listBoxOfDisks_DoubleClick);
            listViewOfFiles.DoubleClick += new EventHandler(listViewOfFiles_DoubleClick);
        }
Пример #2
0
        public void RenameItemClick(KeyValuePair <IEntity, string> renameData)
        {
            if (EntityFunctions.Exists(curDirectory.GetFullName() + @"\" + renameData.Value))
            {
                MessageBox.Show("This file or directory is already exists!");
                return;
            }

            if (renameData.Key.GetType() == EntityType.DIRECTORY || renameData.Key.GetType() == EntityType.FILE || renameData.Key.GetType() == EntityType.ZIP)
            {
                renameData.Key.Rename(curDirectory.GetFullName() + @"\" + renameData.Value);
            }
            else
            {
                renameData.Key.Rename(renameData.Value);
            }
        }
Пример #3
0
        public async Task <List <string> > Do(IEntity curDirect, IEntity selectedItem,
                                              CancellationTokenSource cts = null, Progress <int> progressChanger = null)
        {
            IEntity       item = EntityFunctions.GetItem(curDirect, selectedItem);
            List <string> result;

            if (find == null)
            {
                result = await asyncFind.FindDataAsync(item.GetItemOfAllFiles(), cts, progressChanger);
            }
            else
            {
                result = find.FindData(item.GetItemOfAllFiles(), cts, progressChanger);
            }

            return(result.Distinct().ToList());
        }
Пример #4
0
        public void ArchiveClick(List <IEntity> elements)
        {
            using (ZipFile zip = new ZipFile())
            {
                foreach (IEntity el in elements)
                {
                    zip.AddItem(el.GetFullName());
                }

                int n = 0;
                while (EntityFunctions.Exists(curDirectory.GetFullName() + "\\Archive(" + n + ").zip"))
                {
                    n++;
                }
                zip.Save(curDirectory.GetFullName() + "\\Archive(" + n + ").zip");
            }
        }
Пример #5
0
        public void ThreadsFindClick(IEntity selectedItem)
        {
            var  cts  = new CancellationTokenSource();
            Wait wait = new Wait(cts);

            wait.Show();

            ResOfFindData resOf = new ResOfFindData();
            IParallelFind find  = new ThreadsFind();

            List <string> res = find.FindData(EntityFunctions.GetItem(curDirectory, selectedItem).GetItemOfAllFiles(), cts, new Progress <int>(wait.ChangeProgress));

            foreach (var el in res)
            {
                resOf.AddListEl(el);
            }

            wait.Close();
            resOf.CopyOllInListView();
            resOf.Show();
        }
Пример #6
0
        public bool Copy(IEntity ToDir)
        {
            if (ToDir.GetType() == EntityType.DIRECTORY)
            {
                int k = 1;
                while (Directory.Exists(ToDir + @"\" + Path.GetFileNameWithoutExtension(GetFullName()) + "(" + k + ")" +
                                        Path.GetExtension(GetFullName())))
                {
                    k++;
                }

                return(EntityFunctions.CopyDir(GetFullName(), ToDir + @"\" + Path.GetFileNameWithoutExtension(GetFullName()) + "(" + k + ")" +
                                               Path.GetExtension(GetFullName())));
            }
            else if (ToDir.GetType() == EntityType.ZIPDIRECTORY)
            {
                ZipEntry e = ((EntityZipDirect)ToDir).ZipParent.AddDirectoryInZip(this);
                foreach (var item in ((EntityZipDirect)ToDir).ZipParent.GetItemOfAllFiles())
                {
                    if (item.GetFullName().StartsWith(e.FileName))
                    {
                        item.Rename(ToDir.GetFullName() + '/' + item.GetFullName());
                    }
                }
                e.FileName = ToDir.GetFullName() + '/' + GetName();
                ((EntityZipDirect)ToDir).ZipParent.SaveZip();
                return(true);
            }
            else if (ToDir.GetType() == EntityType.ZIP)
            {
                ((EntityZip)ToDir).AddDirectoryInZip(this);
                return(true);
            }

            return(false);
        }
Пример #7
0
        public void StatisticItemClick(IEntity selectedItem)
        {
            if (selectedItem != null && EntityFunctions.GetExtension(selectedItem) == ".txt")
            {
                string[] strLines;
                if (selectedItem.GetType() == EntityType.ZIPFILE)
                {
                    strLines = ((EntityZipFile)selectedItem).GetFileLines().ToArray();
                }
                else
                {
                    strLines = ((EntityFile)selectedItem).GetFileLines().ToArray();
                }

                string str = "";
                foreach (string s in strLines)
                {
                    str += s;
                }

                var list       = str.Split(new char[] { ' ', '\n', '\r', '.', ',', '!', '?', '-' }, StringSplitOptions.RemoveEmptyEntries);
                int numOfLines = (from w in str.Split('\n') select w).Count();

                var Counts = (from w in list
                              group w by w into g
                              select new { Name = g.Key, Count = g.Count() }).OrderByDescending(j => j.Count).ToList();

                string strInfo = "Num of words - " + list.Count() + "        " + "Num of lines - " + numOfLines + "       " + "Top 10 words -> ";
                for (int i = 0; i < Math.Min(Counts.Count(), 10); i++)
                {
                    strInfo += Counts[i].Name + " ";
                }
                Info info = new Info(strInfo);
                info.Show();
            }
        }
Пример #8
0
        public async void LoadFilesClick(string[] names)
        {
            if (curDirectory == null)
            {
                return;
            }

            var  cts  = new CancellationTokenSource();
            Wait wait = new Wait(cts);

            wait.Show();

            Dictionary <string, Task <string> > books = new Dictionary <string, Task <string> >();

            try
            {
                foreach (string name in names)
                {
                    string          fileName = "";
                    HttpWebResponse fwr      = null;
                    if (!makeFileRequest(name, ref fwr, ref fileName))
                    {
                        wait.Close();
                        return;
                    }
                    books.Add(fileName, readFileAsync(fwr, cts.Token));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error! " + ex.Message);
                wait.Close();
                return;
            }

            var progressIndicator = new Progress <int>(wait.ChangeProgress);
            int count = 0, totalCount = books.Count;

            try
            {
                foreach (var book in books)
                {
                    if (EntityFunctions.Exists(curDirectory.GetFullName() + "\\" + book.Key))
                    {
                        MessageBox.Show("This file is already exists!");
                        return;
                    }

                    EntityFileStream fstream = new EntityFileStream(curDirectory.GetFullName() + "\\" + book.Key);
                    string           str     = await book.Value;
                    ((IProgress <int>)progressIndicator).Report(count * 100 / totalCount);
                    byte[] array = Encoding.Default.GetBytes(str);
                    fstream.Write(array, 0, array.Length);
                    count++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error! " + ex.Message);
                wait.Close();
                return;
            }

            wait.Close();
        }
Пример #9
0
 public void Visit(EntityFile info)
 {
     EntityFunctions.DecryptEntityFile(info, info.cryptKey);
 }
Пример #10
0
 public void Coding()
 {
     username = Encoding.Default.GetString(EntityFunctions.Encrypt(Encoding.Default.GetBytes(username), passToCode));
     password = Encoding.Default.GetString(EntityFunctions.Encrypt(Encoding.Default.GetBytes(password), passToCode));
 }