internal static bool SaveTitleNode(Form1 form, String oldTitle, String newTitle) { TextBox nodeTitleTextBox = form.notePanel.noteTitleTextBox; //TextBox nodeTextTextBox = form.notePanel.nodeTextTextBox; try { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.noFile)); if (CheckNoteTitleExists(form, newTitle)) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("AlreadyExists", className)); nodeTitleTextBox.Text = oldTitle; //GetNotesList(form); //nodeTitleTextBox.Text = oldTitle; //nodeTextTextBox.Text = GetNoteText(form, oldTitle); return(false); } XmlNodeList noteNodeList = xmldoc.GetElementsByTagName("note"); foreach (XmlNode noteNode in noteNodeList) { if (noteNode.ChildNodes[0].InnerText != oldTitle) { continue; } noteNode.ChildNodes[0].InnerText = newTitle; break; } SaveXml(xmldoc, Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.noFile)); } catch (XmlException exception) { ManageError(form, exception); return(false); } return(true); }
private void LoadData() { String directoryName = StringUtil.CheckStringLength(ConstantUtil.ApplicationExecutionPath(), maxCharsNumber); int memoryWorkingSet = Convert.ToInt32(Environment.WorkingSet / 1000); String bits = Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit"; String servicePack = String.IsNullOrEmpty(Environment.OSVersion.ServicePack) ? String.Empty : " " + Environment.OSVersion.ServicePack; usernameLabel.Text = Environment.UserName; domainLabel.Text = Environment.UserDomainName; workingDirectoryLabel.Text = directoryName; machineNameLabel.Text = Environment.MachineName; osLabel.Text = SystemUtil.GetOSDescription(SystemUtil.GetOSInfo()) + servicePack + " " + bits; processorsLabel.Text = Environment.ProcessorCount.ToString(); frameworkVersionLabel.Text = Environment.Version.Major + "." + Environment.Version.Minor + "." + Environment.Version.Build + "." + Environment.Version.Revision; memoryLabel.Text = memoryWorkingSet.ToString("#,###", LanguageUtil.GetInfoCulture()) + " KB"; directoryToolTip.SetToolTip(workingDirectoryLabel, Environment.CurrentDirectory); }
internal static void DeleteExistingFavouriteFile(Form1 form, int filePosition) { String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.fvFile)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); fileContent = splittedFileContent.Where((t, i) => i != filePosition).Aggregate(String.Empty, (current, t) => current + t + Environment.NewLine); //for (int i = 0; i < splittedFileContent.Length; i++) //{ // if (i != filePosition) // { // fileContent = fileContent + splittedFileContent[i] + Environment.NewLine; // } //} SaveFileList(ConstantUtil.fvFile, fileContent); LoadFavouriteFiles(form, true); }
internal static void LoadTrayRecentFiles(Form1 form) { ToolStripMenuItem recentFilesToolStripMenuItem1 = (ToolStripMenuItem)form.trayContextMenuStrip.Items["recentFilesToolStripMenuItem1"]; while (recentFilesToolStripMenuItem1.DropDownItems.Count > 0) { recentFilesToolStripMenuItem1.DropDownItems.Remove(recentFilesToolStripMenuItem1.DropDownItems[0]); } String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.rfFile)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach (String splittedFileContentString in splittedFileContent) { recentFilesToolStripMenuItem1.DropDownItems.Add(splittedFileContentString, null, form.recentFileToolStripMenuItem1_Click); } }
internal static void LoadFavouriteFiles(Form1 form, bool forceLoad, bool shortUrl = false) { ToolStripMenuItem favouriteFilesToolStripMenuItem = form.favouriteFilesToolStripMenuItem; if (!forceLoad && favouriteFilesToolStripMenuItem.DropDownItems.Count > 3) { return; } while (favouriteFilesToolStripMenuItem.DropDownItems.Count > 3) { favouriteFilesToolStripMenuItem.DropDownItems.Remove(favouriteFilesToolStripMenuItem.DropDownItems[3]); } String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.fvFile)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach (String splittedFileContentString in splittedFileContent) { Image icon = null; String text = splittedFileContentString; if (splittedFileContentString.StartsWith(ConstantUtil.sessionPrefix)) { icon = ToolbarResource.session_small; text = text.Substring(ConstantUtil.sessionPrefix.Length); } else if (splittedFileContentString.StartsWith(ConstantUtil.urlPrefix)) { icon = ToolbarResource.url_small; text = text.Substring(ConstantUtil.urlPrefix.Length); } if (shortUrl) { text = StringUtil.CheckStringLength(text, maxCharsNumber); } favouriteFilesToolStripMenuItem.DropDownItems.Add(text, icon, form.favouriteFileToolStripMenuItem_Click); } }
internal static ExtensionObjectList GetExtensionObjectListFromExFile() { ExtensionObjectList extensionObjectList = new ExtensionObjectList(); String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.exFile)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach (String extensionString in splittedFileContent) { separator[0] = "|"; String[] splittedExtensionContent = extensionString.Split(separator, StringSplitOptions.RemoveEmptyEntries); ExtensionObject extensionObject = new ExtensionObject(splittedExtensionContent[0], splittedExtensionContent[1], Convert.ToBoolean(splittedExtensionContent[2])); extensionObjectList.Add(extensionObject); } return(extensionObjectList); }
internal static void RefreshSearchHistory(Form1 form) { int maxNumSearchHistory = ConfigUtil.GetIntParameter("MaxNumSearchHistory"); String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.shFile)); String[] rows = fileContent.Replace(Environment.NewLine, ConstantUtil.newLine).Split(new[] { Convert.ToChar(ConstantUtil.newLine) }, StringSplitOptions.RemoveEmptyEntries); if (rows.Length >= maxNumSearchHistory) { fileContent = String.Empty; for (int i = 0; i < maxNumSearchHistory; i++) { fileContent += rows[i] + Environment.NewLine; } } SaveFileList(ConstantUtil.shFile, fileContent); LoadSearchHistory(form); }
private static void LoadButtonFiles(Form1 form, ToolStripDropDownItem toolStripMenuItem, String file, FileType fileType) { while (toolStripMenuItem.DropDownItems.Count > 0) { toolStripMenuItem.DropDownItems.Remove(toolStripMenuItem.DropDownItems[0]); } String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), file)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach (String splittedFileContentString in splittedFileContent) { switch (fileType) { case FileType.Recent: toolStripMenuItem.DropDownItems.Add(StringUtil.CheckStringLength(splittedFileContentString, maxCharsNumber), null, form.recentFileToolStripMenuItem_Click); break; case FileType.Favourite: Image icon = null; String text = splittedFileContentString; if (splittedFileContentString.StartsWith(ConstantUtil.sessionPrefix)) { icon = ToolbarResource.session_small; text = text.Substring(ConstantUtil.sessionPrefix.Length); } else if (splittedFileContentString.StartsWith(ConstantUtil.urlPrefix)) { icon = ToolbarResource.url_small; text = text.Substring(ConstantUtil.urlPrefix.Length); } toolStripMenuItem.DropDownItems.Add(StringUtil.CheckStringLength(text, maxCharsNumber), icon, form.favouriteFileToolStripMenuItem_Click); break; } } }
public static void Main() { try { String controlTempPath = Path.Combine(ConstantUtil.ApplicationExecutionPath(), "UpdateControl"); if (Directory.Exists(controlTempPath)) { Directory.Delete(controlTempPath, true); } } catch (Exception) { //String error = "Error during \"UpdateControl\" directory deletion." + Environment.NewLine + "Maybe it's in use."; //ProgramException exception = new ProgramException(error); //WindowManager.ShowErrorProgramBox(null, error, exception); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += Main_ThreadExceptionEventHandler; if (!CheckPermissions()) { Application.DoEvents(); Application.Exit(); } else { #if Debug Application.Run(new Form1()); return; #endif String[] args = Environment.GetCommandLineArgs(); SingleInstanceController controller = new SingleInstanceController(); controller.Run(args); } }
internal static void MoveNoteDownOrLast(Form1 form, bool last = false) { TreeView notesTreeView = form.notePanel.notesTreeView; TreeNode selectedNode = notesTreeView.SelectedNode; int selectedNodeIndex = notesTreeView.SelectedNode.Index; if (selectedNodeIndex >= notesTreeView.Nodes.Count - 1) { return; } try { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.noFile)); notesTreeView.Nodes.Remove(selectedNode); notesTreeView.Nodes.Insert(last ? notesTreeView.Nodes.Count : selectedNodeIndex + 1, selectedNode); notesTreeView.SelectedNode = selectedNode; //Save XML XmlNodeList notesNodeList = xmldoc.GetElementsByTagName("notes"); XmlNodeList nodeNodeList = xmldoc.GetElementsByTagName("note"); XmlNode selectedNodeXml = nodeNodeList[selectedNodeIndex]; notesNodeList[0].RemoveChild(nodeNodeList[selectedNodeIndex]); notesNodeList[0].InsertAfter(selectedNodeXml, last ? nodeNodeList[notesTreeView.Nodes.Count - 2] : nodeNodeList[selectedNodeIndex]); SaveXml(xmldoc, Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.noFile)); } catch (XmlException exception) { ManageError(form, exception); } }
internal static String GetFileDialogFilter(out int defaultExtension, out String defaultExtensionShortString) { String filter = String.Empty; defaultExtension = -1; defaultExtensionShortString = "*.*"; String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.exFile)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < splittedFileContent.Length; i++) //Text document|txt|True { String extensionString = splittedFileContent[i]; separator[0] = "|"; String[] splittedExtensionContent = extensionString.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (i != 0) { filter += "|"; } filter += String.Format("{0} (*.{1})|*.{1}", splittedExtensionContent[0], splittedExtensionContent[1]); if (!Convert.ToBoolean(splittedExtensionContent[2])) { continue; } defaultExtensionShortString = String.Format("*.{0}", splittedExtensionContent[1]); defaultExtension = i; } return(filter); }
internal static void LoadRecentSessions(Form1 form, bool forceLoad) { ToolStripMenuItem recentSessionsToolStripMenuItem = form.recentSessionsToolStripMenuItem; if (!forceLoad && recentSessionsToolStripMenuItem.DropDownItems.Count > 3) { return; } while (recentSessionsToolStripMenuItem.DropDownItems.Count > 3) { recentSessionsToolStripMenuItem.DropDownItems.Remove(recentSessionsToolStripMenuItem.DropDownItems[3]); } String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.rsFile)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach (String splittedFileContentString in splittedFileContent) { recentSessionsToolStripMenuItem.DropDownItems.Add(splittedFileContentString, ToolbarResource.session_small, form.recentSessionToolStripMenuItem_Click); } }
internal static String GetNoteText(Form1 form, String title) { try { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.noFile)); XmlNodeList noteNodeList = xmldoc.GetElementsByTagName("note"); foreach (XmlNode noteNode in noteNodeList) { if (noteNode.ChildNodes[0].InnerText == title) { return(noteNode.ChildNodes[1].InnerText); } } } catch (XmlException exception) { ManageError(form, exception); } return(String.Empty); }
private static bool CheckPermissions() { String user = String.Format(@"{0}\{1}", Environment.UserDomainName, Environment.UserName); AuthorizationRuleCollection collection = Directory.GetAccessControl(Path.Combine(ConstantUtil.ApplicationExecutionPath(), "DtPad.exe")).GetAccessRules(true, true, typeof(NTAccount)); if (collection.Cast <FileSystemAccessRule>().Any(rule => rule.IdentityReference.Value.ToLower() == user.ToLower() && rule.AccessControlType == AccessControlType.Allow && rule.FileSystemRights == FileSystemRights.FullControl)) { return(true); } //foreach (FileSystemAccessRule rule in collection) //{ // if (rule.IdentityReference.Value.ToLower() == user.ToLower() && rule.AccessControlType == AccessControlType.Allow && rule.FileSystemRights == FileSystemRights.FullControl) // { // return true; // } //} if (!SystemUtil.IsUserAdministrator()) { WindowManager.ShowAlertBox(null, "DtPad need to be executed (only once!) as Administrator to set permissions." + Environment.NewLine + Environment.NewLine + "Program will now close. Please, restart it as Administrator."); return(false); } DirectoryUtil.SetDirPermissions(ConstantUtil.ApplicationExecutionPath()); foreach (String directory in DirectoryUtil.GetDirectories(ConstantUtil.ApplicationExecutionPath(), "*", SearchOption.AllDirectories)) { DirectoryUtil.SetDirPermissions(directory); } foreach (String file in FileUtil.GetFiles(ConstantUtil.ApplicationExecutionPath(), "*.*", SearchOption.AllDirectories)) { FileUtil.SetFilePermissions(file); } return(true); }
internal static ToolObjectList LoadToolsList(Tools form) { TreeView toolTreeView = form.toolTreeView; TextBox descriptionTextBox = form.descriptionTextBox; TextBox commandLineTextBox = form.commandLineTextBox; TextBox workingFolderTextBox = form.workingFolderTextBox; ComboBox runComboBox = form.runComboBox; Button removeButton = form.removeButton; ToolObjectList toolObjectList = new ToolObjectList(); String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.toFile)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (splittedFileContent.Length > 0) { toolTreeView.BeginUpdate(); } foreach (String toolString in splittedFileContent) { separator[0] = "|"; String[] splittedExtensionContent = toolString.Split(separator, StringSplitOptions.None); if (splittedExtensionContent.Length != 4) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("ErrorReading", className)); FileListManager.SaveFileList(ConstantUtil.toFile, String.Empty); return(LoadToolsList(form)); } toolTreeView.Nodes.Add(splittedExtensionContent[0]); //DtPad ToolObject toolObject = new ToolObject(splittedExtensionContent[0], splittedExtensionContent[1], splittedExtensionContent[2], Convert.ToInt32(splittedExtensionContent[3])); toolObjectList.Add(toolObject); } if (splittedFileContent.Length > 0) { toolTreeView.EndUpdate(); } toolTreeView.Focus(); if (toolTreeView.Nodes.Count > 0) { toolTreeView.SelectedNode = toolTreeView.Nodes[0]; } else { descriptionTextBox.Enabled = false; commandLineTextBox.Enabled = false; workingFolderTextBox.Enabled = false; runComboBox.Enabled = false; runComboBox.SelectedIndex = 0; removeButton.Enabled = false; } return(toolObjectList); }
internal static void CheckWordCorrectness(TextBox wordTextBox, String languageSign, TextBox contentTextBox) { String word = wordTextBox.Text.Trim(); if (String.IsNullOrEmpty(word)) { return; } if (!String.IsNullOrEmpty(contentTextBox.Text)) { contentTextBox.Text += "----------------------------" + Environment.NewLine; } contentTextBox.Text += "[" + DateTime.Now.ToLongTimeString() + "] "; using (Hunspell hunspell = new Hunspell(ConstantUtil.ApplicationExecutionPath() + "\\Languages\\" + languageSign + ".aff", ConstantUtil.ApplicationExecutionPath() + "\\Languages\\" + languageSign + ".dic")) { bool correct = hunspell.Spell(word); String correctness; if (correct) { wordTextBox.BackColor = Color.LightGreen; correctness = LanguageUtil.GetCurrentLanguageString("Correct", className); } else { wordTextBox.BackColor = Color.Tomato; correctness = LanguageUtil.GetCurrentLanguageString("Uncorrect", className); } contentTextBox.Text += String.Format(LanguageUtil.GetCurrentLanguageString("Word", className), word, correctness) + Environment.NewLine; //Uncorrect word, search suggestions if (!correct) { List <String> suggestions = hunspell.Suggest(word); contentTextBox.Text += String.Format(LanguageUtil.GetCurrentLanguageString("Tips", className, suggestions.Count), suggestions.Count) + Environment.NewLine; foreach (String suggestion in suggestions) { contentTextBox.Text += String.Format(LanguageUtil.GetCurrentLanguageString("Tip", className), suggestion) + Environment.NewLine; } return; } //Correct word, search meanings and synonyms MyThes thes = new MyThes(ConstantUtil.ApplicationExecutionPath() + "\\Languages\\" + languageSign + "_th.dat"); ThesResult tr = thes.Lookup(word, hunspell); if ((tr == null) || (tr.IsGenerated)) { return; } foreach (ThesMeaning meaning in tr.Meanings) { contentTextBox.Text += String.Format(LanguageUtil.GetCurrentLanguageString("Meaning", className), meaning.Description) + Environment.NewLine; foreach (String synonym in meaning.Synonyms) { contentTextBox.Text += String.Format(LanguageUtil.GetCurrentLanguageString("Synonym", className), synonym) + Environment.NewLine; } } } }
internal static void CheckTextCorrectness(Form1 form, String languageSign) { if (!ExistsDictionary(languageSign)) { WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("NoDictionary", className) + ConstantUtil.dtPadURL + "wikipage?title=Dictionaries"); return; } CustomXtraTabControl pagesTabControl = form.pagesTabControl; CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage); if (RichTextBoxUtil.ContainsUnderlineText(pageTextBox)) { ClearTextCorrectness(pageTextBox); } bool textCorrectness = true; RichTextBox tempRichTextBox = new RichTextBox { BackColor = pageTextBox.BackColor }; //Temporary RichTextBox to avoid too much undo/redo into buffer pageTextBox.SuspendPainting(); tempRichTextBox.Rtf = pageTextBox.Rtf; //Method 1: char parse (more accurate, slower) using (Hunspell hunspell = new Hunspell(ConstantUtil.ApplicationExecutionPath() + "\\Languages\\" + languageSign + ".aff", ConstantUtil.ApplicationExecutionPath() + "\\Languages\\" + languageSign + ".dic")) { int wordStart = 0; StringBuilder word = new StringBuilder(String.Empty); StringBuilder text = new StringBuilder(pageTextBox.Text); for (int i = 0; i < text.Length; i++) { if (text[i] == '\'' || (!Char.IsWhiteSpace(text[i]) && !Char.IsPunctuation(text[i]) && !Char.IsSymbol(text[i]) && !Char.IsSeparator(text[i]))) { word.Append(text[i]); if (i < text.Length - 1) { continue; } } if (!hunspell.Spell(word.ToString()) && !String.IsNullOrEmpty(word.ToString().Trim())) { tempRichTextBox.Select(wordStart, word.Length); tempRichTextBox.SelectionFont = new Font(pageTextBox.Font, FontStyle.Underline); tempRichTextBox.SelectionColor = (pageTextBox.BackColor == Color.Red) ? Color.Yellow : Color.Red; textCorrectness = false; } word = new StringBuilder(String.Empty); wordStart = i + 1; } } //Method 2: word parse (less accurate, faster) //String[] wordsList = pageTextBox.Text.Split(new[] { ' ', Convert.ToChar(ConstantUtil.newLine), '\t', '/', '\\', '.', '?', ';', ',', ':', '(', ')', '[', ']', '{', '}', '\\', '|', '/', '!', '"', '\'', '=' }, StringSplitOptions.RemoveEmptyEntries); //List<String> wordsAlreadySeen = new List<String>(); //using (Hunspell hunspell = new Hunspell(ConstantUtil.ApplicationExecutionPath() + "\\Languages\\" + languageSign + ".aff", ConstantUtil.ApplicationExecutionPath() + "\\Languages\\" + languageSign + ".dic")) //{ // foreach (String word in wordsList) // { // if (wordsAlreadySeen.Contains(word)) // { // continue; // } // wordsAlreadySeen.Add(word); // if (hunspell.Spell(word)) // { // continue; // } // int i = 0; // while (i != -1 && (i = pageTextBox.Text.IndexOf(word, i)) != -1) // { // tempRichTextBox.Select(i, word.Length); // tempRichTextBox.SelectionFont = new Font(pageTextBox.Font, FontStyle.Underline); // tempRichTextBox.SelectionColor = (pageTextBox.BackColor == Color.Red) ? Color.Yellow : Color.Red; // i += word.Length; // } // } //} pageTextBox.IsUnderlining = true; RichTextBoxUtil.ReplaceRTFContent(pageTextBox, tempRichTextBox); pageTextBox.ResumePainting(); tempRichTextBox.Dispose(); TextManager.RefreshUndoRedoExternal(form); if (textCorrectness) { WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("TextCorrect", className)); } }
internal static bool ExistsDictionary(String languageSign) { return((File.Exists(Path.Combine(ConstantUtil.ApplicationExecutionPath(), "Languages\\" + languageSign + ".aff")) && File.Exists(Path.Combine(ConstantUtil.ApplicationExecutionPath(), "Languages\\" + languageSign + ".dic"))) && File.Exists(Path.Combine(ConstantUtil.ApplicationExecutionPath(), "Languages\\" + languageSign + "_th.dat"))); }
internal static void AddContent(Form1 form) { ListBox clipboardListBox = form.clipboardPanel.clipboardListBox; String content; try { if (!Clipboard.ContainsText()) { return; } content = Clipboard.GetText(); } catch (ExternalException exception) { WindowManager.ShowErrorBox(form, exception.Message, exception); return; } String shortContent = content.Replace(ConstantUtil.newLine, " "); shortContent = shortContent.Replace(Environment.NewLine, " "); shortContent = StringUtil.CheckStringLengthEnd(shortContent, maxCharCount); //shortContent.Replace("<", "<"); //shortContent.Replace(">", ">"); if (IsContentAlreadyClipboarded(form, content)) { return; } try { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.clFile)); XmlElement newClip = xmldoc.CreateElement("clip"); XmlElement numberNode = xmldoc.CreateElement("number"); numberNode.InnerText = clipboardListBox.Items.Count.ToString(); newClip.AppendChild(numberNode); XmlElement shortNode = xmldoc.CreateElement("short"); XmlCDataSection shortNodeCData = xmldoc.CreateCDataSection(shortContent); shortNode.InnerText = String.Empty; shortNode.AppendChild(shortNodeCData); XmlElement contentNode = xmldoc.CreateElement("content"); XmlText contentNodeCData = xmldoc.CreateTextNode(content); //XmlCDataSection contentNodeCData = xmldoc.CreateCDataSection(content); contentNode.InnerText = String.Empty; contentNode.AppendChild(contentNodeCData); newClip.AppendChild(shortNode); newClip.AppendChild(contentNode); if (xmldoc.DocumentElement != null) { xmldoc.DocumentElement.InsertAfter(newClip, xmldoc.DocumentElement.LastChild); xmldoc.Save(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.clFile)); clipboardListBox.Items.Add(shortContent); } else { throw new XmlException(); } } catch (XmlException exception) { WindowManager.ShowErrorBox(form, LanguageUtil.GetCurrentLanguageString("ErrorCreation", className), exception); FileListManager.SaveFileList(ConstantUtil.clFile, ConstantUtil.defaultClipboardFileContent); } }
internal static bool UpdaterCheck(out String errorMessage) { errorMessage = String.Empty; String actualVersion = AssemblyUtil.GetExternalAssemblyVersion(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.dtPadUpdater); WebClient webClient = null; String repository = ConstantUtil.repository; #if ReleaseFE repository = ConstantUtil.repositoryFE; #endif try { webClient = ProxyUtil.InitWebClientProxy(); String finalVersion = webClient.DownloadString(String.Format("{0}dtpadupdater-lastversion.log", repository)); if (actualVersion != finalVersion) { if (FileUtil.IsFileInUse("DtPadUpdater.exe")) { errorMessage = String.Format("DtPadUpdater.exe {0}", LanguageUtil.GetCurrentLanguageString("InUse", className)); return(false); } try { Directory.CreateDirectory("UpdateBackup"); Directory.CreateDirectory("UpdateTemp"); File.Copy("DtPadUpdater.exe", Path.Combine("UpdateBackup", "DtPadUpdater.exe")); webClient.DownloadFile(String.Format("{0}dtpadupdater-repository/DtPadUpdater.exe", repository), Path.Combine("UpdateTemp", "DtPadUpdater.exe")); File.Delete("DtPadUpdater.exe"); File.Move(Path.Combine("UpdateTemp", "DtPadUpdater.exe"), "DtPadUpdater.exe"); Directory.Delete("UpdateBackup", true); Directory.Delete("UpdateTemp", true); } catch (Exception) { File.Delete("DtPadUpdater.exe"); File.Move(Path.Combine("UpdateBackup", "DtPadUpdater.exe"), "DtPadUpdater.exe"); Directory.Delete("UpdateBackup", true); Directory.Delete("UpdateTemp", true); errorMessage = LanguageUtil.GetCurrentLanguageString("ErrorDownloadingUpdater", className); return(false); } } } catch (WebException) { errorMessage = LanguageUtil.GetCurrentLanguageString("ErrorConnection", className); return(false); } finally { if (webClient != null) { webClient.Dispose(); } } return(true); }
internal static void ClearObsoleteRecentSessions(Form1 form) { ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel; ToolStripMenuItem recentSessionsToolStripMenuItem = form.recentSessionsToolStripMenuItem; if (recentSessionsToolStripMenuItem.DropDownItems.Count <= 3) { return; } if (WindowManager.ShowQuestionBox(form, LanguageUtil.GetCurrentLanguageString("ClearObsoleteRecentSessions", className)) != DialogResult.Yes) { return; } String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.rsFile)); String newFileContent = String.Empty; int removedOccurences = 0; String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach (String splittedFileContentString in splittedFileContent) { FileInfo fileInfo = new FileInfo(splittedFileContentString); if (fileInfo.Exists) { newFileContent += splittedFileContentString + Environment.NewLine; } else { removedOccurences++; } } SaveFileList(ConstantUtil.rsFile, newFileContent); toolStripStatusLabel.Text = String.Format(LanguageUtil.GetCurrentLanguageString("ObsoleteSessionsRemoved", className, removedOccurences), removedOccurences); LoadRecentSessions(form, true); }
internal static void SetNewRecentFile(Form1 form, String pathAndFileName) { int maxRecentFile = ConfigUtil.GetIntParameter("MaxNumRecentFile"); String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.rfFile)); //Opening-saving file has already been censed into file if (fileContent.IndexOf(pathAndFileName + Environment.NewLine) >= 0) { fileContent = fileContent.Remove(fileContent.IndexOf(pathAndFileName + Environment.NewLine), pathAndFileName.Length + Environment.NewLine.Length); } String[] rows = fileContent.Replace(Environment.NewLine, ConstantUtil.newLine).Split(new[] { Convert.ToChar(ConstantUtil.newLine) }, StringSplitOptions.RemoveEmptyEntries); if (rows.Length >= maxRecentFile) //recentFilesToolStripMenuItem.DropDownItems.Count >= maxRecentFile { fileContent = String.Empty; for (int i = 0; i < maxRecentFile - 1; i++) { fileContent += rows[i] + Environment.NewLine; } } fileContent = pathAndFileName + Environment.NewLine + fileContent; SaveFileList(ConstantUtil.rfFile, fileContent); LoadRecentFiles(form, true); }
internal static bool IsFileFavourite(String filePathAndName, out String fileContent) { fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.fvFile)); return(fileContent.IndexOf(filePathAndName + Environment.NewLine) >= 0); }
internal static void ExportOptions(Form1 form) { ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel; ToolStripProgressBar toolStripProgressBar = form.toolStripProgressBar; FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog { Description = LanguageUtil.GetCurrentLanguageString("folderBrowserDialogDescription", className), RootFolder = Environment.SpecialFolder.ProgramFiles, SelectedPath = FileUtil.GetInitialFolder(form) }; if (folderBrowserDialog.ShowDialog(form) != DialogResult.OK) { return; } toolStripProgressBar.Value = 0; toolStripProgressBar.Visible = true; String zipFileName = String.Format("{0}_{1}_{2}.{3}", ConstantUtil.exportOptionsFileName, AssemblyUtil.AssemblyVersion.Replace(".", String.Empty), DateTimeUtil.GetTodayDateAsString("yyyyMMdd"), ConstantUtil.exportFileExtension); toolStripProgressBar.PerformStep(); FastZip exportFile = new FastZip(); exportFile.CreateZip(Path.Combine(folderBrowserDialog.SelectedPath, zipFileName), ConstantUtil.ApplicationExecutionPath(), true, @"DtPad\.exe\.config|DtPad\.exe\.ex|DtPad\.exe\.fv|DtPad\.exe\.no|DtPad\.exe\.rf|DtPad\.exe\.rp|DtPad\.exe\.rs|DtPad\.exe\.sf|DtPad\.exe\.sh|DtPad\.exe\.tm|DtPad\.exe\.to|DtPad\.exe\.ru"); toolStripProgressBar.PerformStep(); ZipFile exportedFile = null; try { exportedFile = new ZipFile(Path.Combine(folderBrowserDialog.SelectedPath, zipFileName)); exportedFile.BeginUpdate(); exportedFile.SetComment("DtPad - " + AssemblyUtil.AssemblyVersion); exportedFile.CommitUpdate(); } finally { if (exportedFile != null) { exportedFile.Close(); } } toolStripProgressBar.PerformStep(); String exportStatus = String.Format(LanguageUtil.GetCurrentLanguageString("ExportStatusLabel", className), zipFileName); toolStripProgressBar.PerformStep(); toolStripStatusLabel.Text = exportStatus; WindowManager.ShowInfoBox(form, exportStatus + "!"); toolStripProgressBar.Visible = false; }
internal static void UninstallProcedure(Form1 form, String culture) { ProgressBar updateProgressBar = form.updateProgressBar; TextBox updateTextBox = form.updateTextBox; updateProgressBar.Maximum = 0; updateProgressBar.Value = 0; updateProgressBar.Step = 1; try { updateTextBox.AppendText(LanguageUtil.GetCurrentLanguageString("Start", className, culture)); String[] fileFolders = Directory.GetDirectories(ConstantUtil.ApplicationExecutionPath()); updateProgressBar.Maximum += fileFolders.Length; String desktop = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "DtPad.lnk"); if (File.Exists(desktop)) { updateProgressBar.Maximum += 1; } String linkFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "DtPad"); String[] links = new String[0]; if (Directory.Exists(linkFolder)) { links = Directory.GetFiles(linkFolder, "*.*", SearchOption.TopDirectoryOnly); updateProgressBar.Maximum += links.Length; } String[] files = Directory.GetFiles(ConstantUtil.ApplicationExecutionPath(), "*.*", SearchOption.AllDirectories); updateProgressBar.Maximum += files.Length; String sendto = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SendTo), "DtPad.lnk"); if (File.Exists(sendto)) { updateProgressBar.Maximum += 1; } //String openwith = String.Format(@"Software\Classes\*\shell\{0}\command", LanguageUtil.GetCurrentLanguageString("ShellString", className, culture)); if (ExistsRegistry()) { updateProgressBar.Maximum += 1; } //Files updateTextBox.AppendText(Environment.NewLine + LanguageUtil.GetCurrentLanguageString("DeleteFiles", className, culture)); foreach (String file in files) { if (file == Path.Combine(ConstantUtil.ApplicationExecutionPath(), "DtPadUninstaller.exe")) { continue; } FileDelete(file, updateTextBox, updateProgressBar, culture); } //Desktop updateTextBox.AppendText(Environment.NewLine + LanguageUtil.GetCurrentLanguageString("DeleteDesktop", className, culture)); if (File.Exists(desktop)) { FileDelete(desktop, updateTextBox, updateProgressBar, culture); } //Links updateTextBox.AppendText(Environment.NewLine + LanguageUtil.GetCurrentLanguageString("DeleteLinks", className, culture)); foreach (String link in links) { FileDelete(link, updateTextBox, updateProgressBar, culture); } //SendTo if (File.Exists(sendto)) { updateTextBox.AppendText(Environment.NewLine + LanguageUtil.GetCurrentLanguageString("DeleteSendTo", className, culture)); FileDelete(sendto, updateTextBox, updateProgressBar, culture); } //OpenWith if (ExistsRegistry()) { updateTextBox.AppendText(Environment.NewLine + LanguageUtil.GetCurrentLanguageString("DeleteOpenWith", className, culture)); RegistryDelete(updateTextBox, updateProgressBar, culture); } //File folders foreach (String fileFolder in fileFolders) { FolderDelete(fileFolder, updateTextBox, updateProgressBar, culture); } //Link folder if (Directory.Exists(linkFolder)) { FolderDelete(linkFolder, updateTextBox, updateProgressBar, culture); } updateProgressBar.Value = updateProgressBar.Maximum; updateTextBox.AppendText(Environment.NewLine + Environment.NewLine + LanguageUtil.GetCurrentLanguageString("Success", className, culture)); } catch (Exception exception) { updateTextBox.AppendText(Environment.NewLine + Environment.NewLine + LanguageUtil.GetCurrentLanguageString("Error", className, culture) + " " + exception.Message); } }
internal static void SetNewSearchHistory(Form1 form, String searchText) { int maxSearchHistory = ConfigUtil.GetIntParameter("MaxNumSearchHistory"); String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.shFile)); if (fileContent.IndexOf(searchText + Environment.NewLine) >= 0) { return; //Opening-saving file has already been censed into file } String[] rows = fileContent.Replace(Environment.NewLine, ConstantUtil.newLine).Split(new[] { Convert.ToChar(ConstantUtil.newLine) }, StringSplitOptions.RemoveEmptyEntries); if (rows.Length >= maxSearchHistory) //historyToolStripDropDownButton.DropDownItems.Count >= maxRecentFile { fileContent = String.Empty; for (int i = 0; i < maxSearchHistory - 1; i++) { fileContent += rows[i] + Environment.NewLine; } } fileContent = searchText + Environment.NewLine + fileContent; SaveFileList(ConstantUtil.shFile, fileContent); LoadSearchHistory(form); }
internal static void SetNewRecentURL(UrlEntry form, String urlAddress) { int maxRecentURLs = ConfigUtil.GetIntParameter("MaxNumRecentFile"); String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.ruFile)); //Opening-saving file has already been censed into file if (fileContent.IndexOf(urlAddress + Environment.NewLine) >= 0) { fileContent = fileContent.Remove(fileContent.IndexOf(urlAddress + Environment.NewLine), urlAddress.Length + Environment.NewLine.Length); } String[] rows = fileContent.Replace(Environment.NewLine, ConstantUtil.newLine).Split(new[] { Convert.ToChar(ConstantUtil.newLine) }, StringSplitOptions.RemoveEmptyEntries); if (rows.Length >= maxRecentURLs) { fileContent = String.Empty; for (int i = 0; i < maxRecentURLs - 1; i++) { fileContent += rows[i] + Environment.NewLine; } } fileContent = urlAddress + Environment.NewLine + fileContent; SaveFileList(ConstantUtil.ruFile, fileContent); LoadRecentURLs(form); }
internal static void ImportSessionFromZip(Form1 form) { OpenFileDialog openFileDialog = form.openFileDialog; ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel; ToolStripProgressBar toolStripProgressBar = form.toolStripProgressBar; openFileDialog.InitialDirectory = ConstantUtil.ApplicationExecutionPath(); openFileDialog.Multiselect = false; openFileDialog.Filter = String.Format("{0} (*.zip)|*.zip", LanguageUtil.GetCurrentLanguageString("ExportSessionDescription", className)); //DtPad session archive (*.zip)|*.zip openFileDialog.FileName = "*.zip"; if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } String dpsFileName = String.Empty; ZipFile toImportFile = null; try { toImportFile = new ZipFile(openFileDialog.FileName); foreach (ZipEntry zipEntry in toImportFile) { if (!zipEntry.Name.EndsWith(".dps")) { continue; } dpsFileName = zipEntry.Name; break; } if (String.IsNullOrEmpty(dpsFileName)) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("ArchiveNotExport", className)); return; } } finally { if (toImportFile != null) { toImportFile.Close(); } } FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog { Description = LanguageUtil.GetCurrentLanguageString("folderBrowserDialogDescription", className), RootFolder = Environment.SpecialFolder.MyDocuments, SelectedPath = FileUtil.GetInitialFolder(form) }; if (folderBrowserDialog.ShowDialog(form) != DialogResult.OK) { return; } toolStripProgressBar.Value = 0; toolStripProgressBar.Visible = true; FastZipEvents events = new FastZipEvents { ProcessFile = ProcessFileMethod }; FastZip importFile = new FastZip(events); toolStripProgressBar.PerformStep(); importFile.ExtractZip(openFileDialog.FileName, folderBrowserDialog.SelectedPath, FastZip.Overwrite.Prompt, OverwritePrompt, String.Empty, String.Empty, true); yesAllImportSession = false; if (stopImportSession) { toolStripProgressBar.PerformStep(); toolStripProgressBar.PerformStep(); toolStripProgressBar.Visible = false; return; } toolStripProgressBar.PerformStep(); String importStatus = String.Format(LanguageUtil.GetCurrentLanguageString("ImportStatusLabel", className), openFileDialog.FileName); toolStripProgressBar.PerformStep(); toolStripProgressBar.PerformStep(); toolStripStatusLabel.Text = importStatus; WindowManager.ShowInfoBox(form, importStatus + "!"); toolStripProgressBar.Visible = false; OpenSession(form, Path.Combine(folderBrowserDialog.SelectedPath, dpsFileName)); }
internal static ToolObjectList GetToolObjectListFromToFile(Form form) { try { ToolObjectList toolObjectList = new ToolObjectList(); String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.toFile)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach (String extensionString in splittedFileContent) { separator[0] = "|"; String[] splittedExtensionContent = extensionString.Split(separator, StringSplitOptions.None); ToolObject toolObject = new ToolObject(splittedExtensionContent[0], splittedExtensionContent[1], splittedExtensionContent[2], Convert.ToInt32(splittedExtensionContent[3])); toolObjectList.Add(toolObject); } return(toolObjectList); } catch (Exception) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("ErrorReading", className)); FileListManager.SaveFileList(ConstantUtil.toFile, String.Empty); return(GetToolObjectListFromToFile(form)); } }