コード例 #1
0
        public void MoveToDirectory(ListView list, bool left)
        {
            string currentPath;

            if (left)
            {
                currentPath = CurrentPath1;
            }
            else
            {
                currentPath = CurrentPath2;
            }
            for (int i = 0; i < list.Items.Count; i++)
            {
                if (list.Items[i].ImageIndex == 1)
                {
                    string name;
                    if (list.Items[i].Text.LastIndexOf(".") == -1)
                    {
                        name = "withoutExtension";
                    }
                    else
                    {
                        name = list.Items[i].Text.Substring(list.Items[i].Text.LastIndexOf(".") + 1);
                    }
                    Folder folder = new Folder(currentPath + "\\" + name);
                    if (!folder.isExist())
                    {
                        Directory.CreateDirectory(currentPath + "\\" + name);
                    }
                    CommonFile comFile = new CommonFile(currentPath + "\\" + list.Items[i].Text);
                    comFile.Move(currentPath + "\\" + name);
                }
            }
        }
コード例 #2
0
        public void addToBuffer(ListView list, bool left)
        {
            string CurrentPath;

            if (left)
            {
                CurrentPath = currentPath1;
            }
            else
            {
                CurrentPath = currentPath2;
            }
            foldersToCopy.Clear();
            filesToCopy.Clear();
            if (list.SelectedItems.Count > 0)
            {
                foreach (int i in list.SelectedIndices)
                {
                    if (list.Items[i].ImageIndex == 0)
                    {
                        Folder folder = new Folder(CurrentPath + "\\" + list.Items[i].Text);
                        foldersToCopy.Add(folder);
                    }
                    else
                    {
                        CommonFile file = new CommonFile(CurrentPath + "\\" + list.Items[i].Text);
                        filesToCopy.Add(file);
                    }
                }
            }
        }
コード例 #3
0
        public void Delete(ListView list, bool left)
        {
            string CurrentPath;

            if (left)
            {
                CurrentPath = currentPath1;
            }
            else
            {
                CurrentPath = currentPath2;
            }
            if (list.SelectedItems.Count > 0)
            {
                foreach (int i in list.SelectedIndices)
                {
                    if (list.Items[i].ImageIndex == 0)
                    {
                        Folder folder = new Folder(CurrentPath + "\\" + list.Items[i].Text);
                        folder.Delete();
                    }
                    else
                    {
                        CommonFile file = new CommonFile(CurrentPath + "\\" + list.Items[i].Text);
                        file.Delete();
                    }
                }
            }
        }
コード例 #4
0
ファイル: Presenter.cs プロジェクト: ihorrohi/file-manager
        public void Merging(ListView list, bool left)
        {
            if (contentForMerging == "")
            {
                MessageBox.Show("Please select html file", "Oops..");
                return;
            }
            string path = list.SelectedItems[0].Text;
            string currentPath;

            if (left)
            {
                currentPath = String.Format(@"{0}\\{1}", currentPath1, path);
            }
            else
            {
                currentPath = String.Format(@"{0}\\{1}", currentPath2, path);
            }
            if (list.SelectedItems[0].ImageIndex == 0)
            {
                MessageBox.Show("You haven`t chosen a html1 file", "Oops...");
            }
            else
            {
                try
                {
                    CommonFile commonFile = new CommonFile(currentPath);
                    if (currentPath.Substring(currentPath.LastIndexOf(".") + 1) == "html")
                    {
                        filesToCopy.Clear();
                        string content = commonFile.GetText(new HtmlFile(currentPath));
                        if (GetPathesOfImg(content) && GetPathesOfImg(contentForMerging))
                        {
                            ProcessMerging(currentPath);
                            File.AppendAllText(currentPath, contentForMerging);
                        }
                        else
                        {
                            contentForMerging = "";
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("You haven`t chosen a html file", "Oops...");
                    }
                }
                catch (Exception error)
                {
                    contentForMerging = "";
                    MessageBox.Show(error.Message.ToString(), "Error");
                }
            }
            MessageBox.Show("Merging complete", "Result");
            contentForMerging = "";
        }
コード例 #5
0
 public CommonFile[] GetFiles()
 {
     string[]     strFiles = Directory.GetFiles(Path);
     CommonFile[] files    = new CommonFile[strFiles.Length];
     for (int i = 0; i < strFiles.Length; i++)
     {
         files[i] = new CommonFile(strFiles[i]);
     }
     return(files);
 }
コード例 #6
0
ファイル: Presenter.cs プロジェクト: ihorrohi/file-manager
        static public void OpenResult(ListView list)
        {
            string currentpath = pathes[0].Substring(0, pathes[0].LastIndexOf('\\') + 1);
            string path        = list.SelectedItems[0].Text;

            currentpath = currentpath + path;
            CommonFile commonFile = new CommonFile(currentpath);
            string     content;

            content = commonFile.GetText(new HtmlFile(currentpath));
            TextEditorForm HEdit = new TextEditorForm(content, currentpath, true);

            HEdit.ShowDialog();
        }
コード例 #7
0
        public void SelectSentenses(ListView list, bool left)
        {
            string currentPath;

            if (left)
            {
                currentPath = CurrentPath1;
            }
            else
            {
                currentPath = CurrentPath2;
            }
            string content = " ";

            if (list.SelectedItems.Count > 0)
            {
                foreach (int i in list.SelectedIndices)
                {
                    if (list.Items[i].ImageIndex == 0)
                    {
                        continue;
                    }
                    else
                    {
                        string     curP = list.Items[i].Text;
                        CommonFile cf   = new CommonFile(currentPath + "\\" + list.Items[i].Text);
                        if (curP.Substring(curP.LastIndexOf(".") + 1) == "txt")
                        {
                            string sent = cf.GetText(new TxtFile(currentPath + "\\" + list.Items[i].Text));
                            content += Presenter.threeSentenses(sent);
                        }
                        else if (curP.Substring(curP.LastIndexOf(".") + 1) == "xml")
                        {
                            string sent = cf.GetText(new XmlFile(currentPath + "\\" + list.Items[i].Text));
                            content += Presenter.threeSentenses(sent);
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                Clipboard.SetText(content);
            }
        }
コード例 #8
0
ファイル: Presenter.cs プロジェクト: ihorrohi/file-manager
        public bool StartSearch(string path, string key)
        {
            CommonFile commonFile = new CommonFile(path);
            string     content    = commonFile.GetText(new HtmlFile(path));

            content = content.ToLower();
            key     = key.ToLower();
            MatchCollection matches = Regex.Matches(content, @"(<\s*title[^>]*>(.*?)<\s*\/\s*title>)");

            foreach (var match in matches)
            {
                if (match.ToString().Contains(key))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #9
0
        public void refreshWithExtension(ListView list, string path, string ext)
        {
            Folder folder = new Folder(path);

            Folder[] folders = folder.GetFolders();
            list.Items.Clear();
            ListViewItem.ListViewSubItem[] subItems;
            string dirName = "";

            for (int i = 0; i < folders.Length; i++)
            {
                dirName = folders[i].Name;
                ListViewItem item = new ListViewItem(dirName, 0);
                subItems = new ListViewItem.ListViewSubItem[] {
                    new ListViewItem.ListViewSubItem(item, "FOLDER"),
                    new ListViewItem.ListViewSubItem(item,
                                                     String.Format("{0}", Directory.GetCreationTime(path + "\\" + dirName)))
                };
                item.SubItems.AddRange(subItems);
                list.Items.Add(item);
            }
            CommonFile file = new CommonFile(path);

            CommonFile[] files    = file.GetFiles();
            string       fileName = "";

            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Name.Substring(files[i].Name.LastIndexOf(".") + 1) == ext)
                {
                    fileName = files[i].Name;
                    ListViewItem item = new ListViewItem(fileName, 1);
                    subItems = new ListViewItem.ListViewSubItem[] {
                        new ListViewItem.ListViewSubItem(item, "FILE"),
                        new ListViewItem.ListViewSubItem(item,
                                                         String.Format("{0}", File.GetCreationTime(path + "\\" + fileName)))
                    };
                    item.SubItems.AddRange(subItems);
                    list.Items.Add(item);
                }
            }
            list.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }
コード例 #10
0
ファイル: Presenter.cs プロジェクト: ihorrohi/file-manager
        public void Delete(ListView list, bool left)
        {
            string currentPath;

            if (left)
            {
                currentPath = currentPath1;
            }
            else
            {
                currentPath = currentPath2;
            }
            WarningForm warningForm = new WarningForm(false);

            warningForm.ShowDialog();
            if (warningForm.action)
            {
                if (list.SelectedItems.Count > 0)
                {
                    foreach (int i in list.SelectedIndices)
                    {
                        if (list.Items[i].ImageIndex == 0)
                        {
                            Folder folder = new Folder(currentPath + "\\" + list.Items[i].Text);
                            folder.Delete();
                            director.DeleteReport(currentPath + "\\" + list.Items[i].Text);
                            director.BuildReport();
                            reports.Add(director.GetReportItem());
                        }
                        else
                        {
                            CommonFile file = new CommonFile(currentPath + "\\" + list.Items[i].Text);
                            file.Delete();
                            director.DeleteReport(currentPath + "\\" + list.Items[i].Text);
                            director.BuildReport();
                            reports.Add(director.GetReportItem());
                        }
                    }
                }
            }
        }
コード例 #11
0
ファイル: Presenter.cs プロジェクト: ihorrohi/file-manager
        public void Select(ListView list, bool left)
        {
            string path = list.SelectedItems[0].Text;
            string currentPath;

            if (left)
            {
                currentPath = String.Format(@"{0}\\{1}", currentPath1, path);
            }
            else
            {
                currentPath = String.Format(@"{0}\\{1}", currentPath2, path);
            }
            if (list.SelectedItems[0].ImageIndex == 0)
            {
                MessageBox.Show("You haven`t chosen a html1 file", "Oops...");
            }
            else
            {
                try
                {
                    CommonFile cf = new CommonFile(currentPath);
                    if (currentPath.Substring(currentPath.LastIndexOf(".") + 1) == "html")
                    {
                        contentForMerging = cf.GetText(new HtmlFile(currentPath));
                    }
                    else
                    {
                        MessageBox.Show("You haven`t chosen a html file", "Oops...");
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show(error.Message.ToString(), "Error");
                }
            }
        }
コード例 #12
0
ファイル: Presenter.cs プロジェクト: ihorrohi/file-manager
        public void WordsIncludesInFile(ListView list, bool left)
        {
            string currentPath;

            if (left)
            {
                currentPath = CurrentPath1;
            }
            else
            {
                currentPath = CurrentPath2;
            }
            if (list.SelectedItems.Count > 0)
            {
                foreach (int i in list.SelectedIndices)
                {
                    if (list.Items[i].ImageIndex == 0)
                    {
                        continue;
                    }
                    else
                    {
                        string     currentPosition = list.Items[i].Text;
                        CommonFile commonFile      = new CommonFile(currentPath + "\\" + list.Items[i].Text);
                        if (currentPosition.Substring(currentPosition.LastIndexOf(".") + 1) == "txt")
                        {
                            string sent = commonFile.GetText(new TxtFile(currentPath + "\\" + list.Items[i].Text));
                            Presenter.SearchWordIncludes(sent);
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
        }
コード例 #13
0
ファイル: Presenter.cs プロジェクト: ihorrohi/file-manager
        public bool GetPathesOfImg(string content)
        {
            string        text    = content;
            string        pattern = "<img.+?src=[\"'](.+?)[\"'].*?>";
            List <string> pathes  = new List <string>();
            Regex         regex   = new Regex(pattern, RegexOptions.IgnoreCase);
            Match         match   = regex.Match(text);

            while (match.Success)
            {
                pathes.Add(match.Groups[1].Value);
                match = match.NextMatch();
            }
            foreach (var imgPath in pathes)
            {
                if (Regex.IsMatch(imgPath.ToString(), @"^(?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w.$]+)\\(?:[\w]+\\)*\w([\w.])+$"))
                {
                    if (File.Exists(imgPath.ToString()))
                    {
                        CommonFile currcommonFile = new CommonFile(imgPath.ToString());
                        filesToCopy.Add(currcommonFile);
                    }
                    else
                    {
                        MessageBox.Show("Html file exists inadmissble pathes!", "Oops");
                        return(false);
                    }
                }
                else
                {
                    MessageBox.Show("Html file exists inadmissble pathes!", "Oops");
                    return(false);
                }
            }
            return(true);
        }
コード例 #14
0
        public void openItem(ListView list, bool left)
        {
            string path = list.SelectedItems[0].Text;
            string currentPath;

            if (left)
            {
                currentPath = String.Format(@"{0}\\{1}", currentPath1, path);
            }
            else
            {
                currentPath = String.Format(@"{0}\\{1}", currentPath2, path);
            }
            if (list.SelectedItems[0].ImageIndex == 0)
            {
                try
                {
                    refresh(list, currentPath);
                    if (left)
                    {
                        currentPath1 = currentPath;
                    }
                    else
                    {
                        currentPath2 = currentPath;
                    }
                }
                catch (IOException ex)
                {
                    refresh(list, currentPath1);
                }
                catch (UnauthorizedAccessException ex)
                {
                    MessageBox.Show("В доступі відказано", "ERROR");
                }
            }
            else
            {
                try
                {
                    CommonFile cf = new CommonFile(currentPath);
                    string     content;
                    if (currentPath.Substring(currentPath.LastIndexOf(".") + 1) == "txt")
                    {
                        content = cf.GetText(new TxtFile(currentPath));
                        TextEditor TEdit = new TextEditor(content, currentPath);
                        TEdit.ShowDialog();
                    }
                    else if (currentPath.Substring(currentPath.LastIndexOf(".") + 1) == "xml")
                    {
                        content = cf.GetText(new XmlFile(currentPath));
                        TextEditor TEdit = new TextEditor(content, currentPath);
                        TEdit.ShowDialog();
                    }
                    else
                    {
                        Process.Start(currentPath);
                    }
                }
                catch
                {
                    MessageBox.Show("В доступі до файлу відказано");
                }
            }
        }
コード例 #15
0
ファイル: Presenter.cs プロジェクト: ihorrohi/file-manager
        public void Move(ListView list, bool left)
        {
            string currentPath;

            if (left)
            {
                currentPath = currentPath1;
            }
            else
            {
                currentPath = currentPath2;
            }
            if (list.SelectedItems.Count > 0)
            {
                foreach (int i in list.SelectedIndices)
                {
                    if (list.Items[i].ImageIndex == 0)
                    {
                        Folder folder = new Folder(currentPath + "\\" + list.Items[i].Text);
                        if (left)
                        {
                            if (!Directory.Exists(currentPath2 + "\\" + list.Items[i].Text))
                            {
                                folder.Move(currentPath2);
                                director.MoveReport(currentPath + "\\" + list.Items[i].Text, currentPath2 + "\\" + list.Items[i].Text);
                                director.BuildReport();
                                reports.Add(director.GetReportItem());
                            }
                            else
                            {
                                MessageBox.Show("The folder is already exists", "Error");
                            }
                        }
                        else
                        {
                            if (!Directory.Exists(currentPath1 + "\\" + list.Items[i].Text))
                            {
                                folder.Move(currentPath1);
                                director.MoveReport(currentPath + "\\" + list.Items[i].Text, currentPath1 + "\\" + list.Items[i].Text);
                                director.BuildReport();
                                reports.Add(director.GetReportItem());
                            }
                            else
                            {
                                MessageBox.Show("The folder is already exists", "Error");
                            }
                        }
                    }
                    else
                    {
                        CommonFile file = new CommonFile(currentPath + "\\" + list.Items[i].Text);
                        if (left)
                        {
                            if (!File.Exists(currentPath2 + "\\" + list.Items[i].Text))
                            {
                                file.Move(currentPath2);
                                director.MoveReport(currentPath + "\\" + list.Items[i].Text, currentPath2 + "\\" + list.Items[i].Text);
                                director.BuildReport();
                                reports.Add(director.GetReportItem());
                            }
                            else
                            {
                                MessageBox.Show("The file is already exists", "Error");
                            }
                        }
                        else
                        {
                            if (!File.Exists(currentPath1 + "\\" + list.Items[i].Text))
                            {
                                file.Move(currentPath1);
                                director.MoveReport(currentPath + "\\" + list.Items[i].Text, currentPath1 + "\\" + list.Items[i].Text);
                                director.BuildReport();
                                reports.Add(director.GetReportItem());
                            }
                            else
                            {
                                MessageBox.Show("The file is already exists", "Error");
                            }
                        }
                    }
                }
            }
        }
コード例 #16
0
ファイル: Presenter.cs プロジェクト: ihorrohi/file-manager
        public void Rename(ListView list, bool left)
        {
            string path = list.SelectedItems[0].Text;
            string currentPath;

            if (left)
            {
                currentPath = String.Format(@"{0}\\{1}", currentPath1, path);
            }
            else
            {
                currentPath = String.Format(@"{0}\\{1}", currentPath2, path);
            }
            LabelForm labelForm = new LabelForm(-1);

            labelForm.ShowDialog();
            try
            {
                if (list.SelectedItems[0].ImageIndex == 0)
                {
                    if (labelForm.done)
                    {
                        if (!Directory.Exists(currentPath + "\\" + labelForm.text))
                        {
                            Folder folder = new Folder(currentPath);
                            folder.Rename(labelForm.text);
                            director.RenameReport(path, labelForm.text);
                            director.BuildReport();
                            reports.Add(director.GetReportItem());
                        }
                        else
                        {
                            MessageBox.Show("Such a folder is already exists", "Error");
                        }
                    }
                }
                else
                {
                    if (!File.Exists(currentPath + "\\" + labelForm.text))
                    {
                        if (labelForm.done)
                        {
                            CommonFile commonFile = new CommonFile(currentPath);
                            commonFile.Rename(labelForm.text);
                            director.RenameReport(path, labelForm.text);
                            director.BuildReport();
                            reports.Add(director.GetReportItem());
                        }
                        labelForm.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("Such a file is already exists", "Error");
                    }
                }
            }
            catch (Exception error)
            {
                labelForm.Dispose();
                MessageBox.Show(error.Message.ToString(), "Error");
            }
        }
コード例 #17
0
 public string GetText(CommonFile ComFile)
 {
     return(ComFile.GetContent());
 }
コード例 #18
0
ファイル: Presenter.cs プロジェクト: ihorrohi/file-manager
        public void OpenItem(ListView list, bool left)
        {
            string path = list.SelectedItems[0].Text;
            string currentPath;

            if (left)
            {
                currentPath = String.Format(@"{0}\\{1}", currentPath1, path);
            }
            else
            {
                currentPath = String.Format(@"{0}\\{1}", currentPath2, path);
            }
            if (list.SelectedItems[0].ImageIndex == 0)
            {
                try
                {
                    Refresh(list, currentPath);
                    if (left)
                    {
                        currentPath1 = currentPath;
                    }
                    else
                    {
                        currentPath2 = currentPath;
                    }
                }
                catch (IOException ex)
                {
                    Refresh(list, currentPath1);
                }
                catch (UnauthorizedAccessException ex)
                {
                    MessageBox.Show("You haven`t access", "Error");
                }
                director.OpenReport(currentPath);
                director.BuildReport();
                reports.Add(director.GetReportItem());
            }
            else
            {
                try
                {
                    CommonFile cf = new CommonFile(currentPath);
                    string     content;
                    if (currentPath.Substring(currentPath.LastIndexOf(".") + 1) == "txt")
                    {
                        content = cf.GetText(new TxtFile(currentPath));
                        TextEditorForm TEdit = new TextEditorForm(content, currentPath, false);
                        TEdit.ShowDialog();
                    }
                    else if (currentPath.Substring(currentPath.LastIndexOf(".") + 1) == "html")
                    {
                        content = cf.GetText(new HtmlFile(currentPath));
                        TextEditorForm HEdit = new TextEditorForm(content, currentPath, false);
                        HEdit.ShowDialog();
                    }
                    else
                    {
                        Process.Start(currentPath);
                    }
                    director.OpenReport(path);
                    director.BuildReport();
                    reports.Add(director.GetReportItem());
                }
                catch (InvalidOperationException ex)
                {
                    MessageBox.Show("You haven`t access", "Error");
                }
            }
        }