private void btnOK_Click(object sender, EventArgs e) { string newName = textName.Text; if (string.IsNullOrEmpty(newName)) { CppUtils.CenteredMessageBox(this, Properties.Resources.ENTER_FILENAME, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (-1 != newName.IndexOfAny(Program.damemoji.ToCharArray())) { CppUtils.CenteredMessageBox(this, Properties.Resources.FOLLOWING_UNABLE_FILENAME + Environment.NewLine + Environment.NewLine + Program.damemoji, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } this.DialogResult = DialogResult.OK; Close(); }
private void btnStart_Click(object sender, EventArgs e) { IsResultOpenURL = radioOpenUrl.Checked; if (IsResultOpenURL) { return; } ResultURLs = txtEnterURLs.Lines; foreach (string u in ResultURLs) { if (u.IndexOf('[') >= 0 && u.IndexOf(']') >= 0) { if (DialogResult.Yes != CppUtils.CenteredMessageBox(this, Properties.Resources.URL_INCLUDES_BLANCKET_CONTINUE, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { DialogResult = DialogResult.None; return; } } } }
private void btnFindDuplicates_Click(object sender, EventArgs e) { for (int i = 0; i < listUrls.Items.Count; ++i) { int found = findDup(i + 1, listUrls.Items[i].Text); if (found >= 0) { clearSelection(); listUrls.Items[i].Focused = listUrls.Items[i].Selected = true; listUrls.Items[found].Focused = listUrls.Items[found].Selected = true; listUrls.EnsureVisible(i); CppUtils.CenteredMessageBox(this, Properties.Resources.DUPITEM_FOUND, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } CppUtils.CenteredMessageBox(this, Properties.Resources.NO_DUPITEM_FOUND, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void btnAbout_Click(object sender, EventArgs e) { StringBuilder sbMessage = new StringBuilder(); sbMessage.AppendLine(string.Format("{0} v{1}", Application.ProductName, AmbLib.getAssemblyVersion(Assembly.GetExecutingAssembly(), 3))); sbMessage.AppendLine(); sbMessage.AppendLine(AmbLib.getAssemblyCopyright(Assembly.GetExecutingAssembly())); sbMessage.AppendLine(); sbMessage.AppendLine(Program.Url); sbMessage.AppendLine(Properties.Resources.PRESS_CTRL_OK); CppUtils.CenteredMessageBox(this, sbMessage.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); if (CppUtils.IsCtrlPressed()) { try { Process.Start(Program.Url); } catch (Exception ex) { CppUtils.Alert(ex); } } }
private void btnOK_Click(object sender, EventArgs e) { string newName = txtName.Text; if (string.IsNullOrEmpty(newName)) { CppUtils.CenteredMessageBox(this, Properties.Resources.ENTER_FILENAME, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (-1 != newName.IndexOfAny(Program.damemoji.ToCharArray())) { showDamemojiError(); return; } List <Control> backToEnables = disableAll(); if (!Program.RenameIt(this, txtName.Tag.ToString(), newName)) { enableAll(backToEnables); return; } enableAll(backToEnables); this.DialogResult = DialogResult.OK; Close(); }
static void ShowHelp() { CppUtils.CenteredMessageBox(GetHelpMessage(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); }
void Info(string message) { CppUtils.CenteredMessageBox(this, message, ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); }
void Alert(string message) { CppUtils.CenteredMessageBox(this, message, ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); }
void showDamemojiError() { CppUtils.CenteredMessageBox(this, Properties.Resources.FOLLOWING_UNABLE_FILENAME + Environment.NewLine + Program.damemoji, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); }
DialogResult YesOrNo(string message) { return(CppUtils.CenteredMessageBox(this, message, ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question)); }
static void ShowHelp() { CppUtils.CenteredMessageBox(GetHelpMessage(), string.Format("{0} ver{1}", Application.ProductName, AmbLib.getAssemblyVersion(Assembly.GetExecutingAssembly(), 3)), MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { try { Process.Start(listUrls.SelectedItems[0].Text); } catch (Exception ex) { CppUtils.CenteredMessageBox(this, ex.Message, Application.ProductName); } }
// private readonly List<string> generalExt_ = new List<string>( "bin","txt","xml"); private void btnChangeExt_Click(object sender, EventArgs e) { try { { string src = InputFile; FileInfo srcinfo = new FileInfo(src); int extlen = srcinfo.Extension.Length; // What is this? //if (extlen >= 5) // extlen = 0; string srcwithoutext = srcinfo.FullName.Substring(0, srcinfo.FullName.Length - extlen); string ext = txtExt.Text; ext = ext.Split(' ')[0]; string dstname = srcwithoutext + '.' + ext; if (!option.IsSkipWarning) { string message = string.Format(Properties.Resources.Q_RENAME_EXTENSION, string.IsNullOrEmpty(Path.GetExtension(src)) ? Properties.Resources.NO_EXTENSION : Path.GetExtension(src), Path.GetExtension(dstname)); if (DialogResult.Yes != CppUtils.CenteredMessageBox( this, message, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { return; } } srcinfo.MoveTo(dstname); InputFile = dstname; analyzefile(dstname); if (option.IsCloseAfterRenaming) { Close(); return; } } } catch (Exception ex) { CppUtils.CenteredMessageBox(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
static void ShowAlert(string message) { StringBuilder sbMessage = new StringBuilder(); sbMessage.AppendLine(message); sbMessage.AppendLine(); sbMessage.AppendLine(GetHelpMessage()); CppUtils.CenteredMessageBox(sbMessage.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); }
private void tssbInsertURLs_ButtonClick(object sender, EventArgs e) { try { string all = Clipboard.GetText(); txtTmp.Text = all; foreach (string line in txtTmp.Lines) { listUrls.Items.Add(line); } } catch (Exception ex) { CppUtils.CenteredMessageBox(this, ex.Message, Application.ProductName); } }
private void DoTimerStaff() { progMain.Value = _curIndex; //try { string url = _urls[_curIndex]; wbPrint.Navigate(url); waitBrowser(); if (chkPause.Checked) { return; } slStatus.Text = Properties.Resources.PRINTING; waitSimple(decimal.ToInt32(udPrintWait.Value)); wbPrint.Print(); slStatus.Text = ""; waitBrowser(); _waitCounter = (decimal.ToInt32(udWait.Value)); ++_curIndex; UpdateTitle(); progMain.Value = _curIndex; if (_curIndex >= _urls.Count) { this.Focus(); CppUtils.CenteredMessageBox(this, Properties.Resources.DONE, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); return; } } //catch (Exception ex) //{ // CppUtils.CenteredMessageBox(this, ex.Message); //} //finally { //inprocess = false; } }
private void tsbNewItem_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { // ofd.DefaultExt = "exe"; ofd.Filter = @"Executable (.exe)|*.exe|All Files (*.*)|*.*"; if (DialogResult.OK != ofd.ShowDialog()) { return; } FileInfo fi = new FileInfo(ofd.FileName); string shortcutfile = Path.GetFileNameWithoutExtension(fi.Name) + ".lnk"; string shortcutfilefullpath = Path.Combine(CurrentInventoryFolder, shortcutfile); if (System.IO.File.Exists(shortcutfilefullpath)) { if (DialogResult.Yes != YesOrNo( string.Format( Properties.Resources.SHORTCUT_ALREADY_EXISTS, shortcutfilefullpath)) ) { return; } } try { CreateShortcutWSH(shortcutfilefullpath, ofd.FileName); } catch (Exception ex) { var sb = new StringBuilder(); sb.AppendLine(Properties.Resources.SHORTCUT_CREATION_FAILED); sb.AppendLine(ex.Message); CppUtils.CenteredMessageBox( this, sb.ToString(), ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } UpdateList(); } }
private void btnAbout_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0} ver {1}", Application.ProductName, AmbLib.getAssemblyVersion(Assembly.GetExecutingAssembly(), 3)); sb.AppendLine(); sb.AppendLine(Application.CompanyName); sb.Append(AmbLib.getAssemblyCopyright(Assembly.GetExecutingAssembly())); CppUtils.CenteredMessageBox(this, sb.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void btnRun_Click(object sender, EventArgs e) { if (Running) { Cancelling = true; return; } Cancelling = false; if (IsListAllDone()) { if (DialogResult.Yes != CppUtils.YesOrNo( Properties.Resources.DO_IT_AGAIN, MessageBoxDefaultButton.Button2)) { return; } ClearAllListIndicator(); } UpdateCombo(); List <KeyValuePair <string, string> > willExecute = new List <KeyValuePair <string, string> >(); RunAsync(RunAsyncType.RunAsync_DryRun, willExecute); StringBuilder sbFilesAndArgs = new StringBuilder(); for (int i = 0; i < willExecute.Count; ++i) { sbFilesAndArgs.AppendLine(string.Format("File{0}={1}", i, willExecute[i].Key)); sbFilesAndArgs.AppendLine(string.Format("Args{0}={1}", i, willExecute[i].Value)); sbFilesAndArgs.AppendLine(); } StringBuilder sbMessage = new StringBuilder(); sbMessage.AppendLine(Properties.Resources.BEFORE_RUN_MESSAGE); sbMessage.AppendLine(); sbMessage.Append(sbFilesAndArgs); if (DialogResult.Yes != CppUtils.CenteredMessageBox(this, sbMessage.ToString(), Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { return; } RunAsync(RunAsyncType.RunAsync_Normal, null); }
private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); sb.Append(ProductName); sb.Append(" version "); sb.Append(Assembly.GetExecutingAssembly().GetName().Version.Major.ToString()); sb.Append("."); sb.Append(Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString()); CppUtils.CenteredMessageBox(this, sb.ToString(), ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); sb.Append(Application.ProductName); sb.Append(" version "); sb.Append(AmbLib.getAssemblyVersion(Assembly.GetExecutingAssembly(), 3)); sb.AppendLine(); // sb.Append("Copyright 2018 Ambiesoft"); sb.Append(AmbLib.getAssemblyCopyright(Assembly.GetExecutingAssembly())); CppUtils.CenteredMessageBox(this, sb.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void deployRangedURLToolStripMenuItem_Click(object sender, EventArgs e) { try { string all = Clipboard.GetText(); txtTmp.Text = all; foreach (string line in txtTmp.Lines) { string[] deployedlines = getDeployedLines(line); foreach (string dl in deployedlines) { listUrls.Items.Add(dl); } } } catch (Exception ex) { CppUtils.CenteredMessageBox(this, ex.Message, Application.ProductName); } }
private void FormMain_FormClosed(object sender, FormClosedEventArgs e) { bool failed = false; HashIni ini = Profile.ReadAll(IniPath); failed |= !Ambiesoft.Profile.WriteString("option", "ffmpeg", ffmpeg_, ini); failed |= !AmbLib.SaveListViewColumnWidth(lvMain, SECTION_OPTION, KEY_COLUMN_WIDTH, ini); failed |= !AmbLib.SaveFormXYWH(this, SECTION_OPTION, ini); failed |= !Profile.WriteAll(ini, IniPath); if (failed) { CppUtils.CenteredMessageBox(this, Properties.Resources.S_INISAVE_FAILED, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static bool tryMoveFile(string source, string dest, MoveFileOrDirectory moveFunc) { // Loop while retrying for (; ;) { try { moveFunc(source, dest); return(true); } catch (Exception ex) { StringBuilder sbMessage = new StringBuilder(); sbMessage.AppendLine(string.Format(Properties.Resources.FAILED_TO_MOVE_S, source)); sbMessage.AppendLine(); sbMessage.AppendLine(ex.Message); DialogResult result = CppUtils.CenteredMessageBox( sbMessage.ToString(), Application.ProductName, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (result == DialogResult.Abort) { return(false); } else if (result == DialogResult.Retry) { continue; } else if (result == DialogResult.Ignore) { return(true); } else { Debug.Assert(false); return(false); } } } }
private void tsCopyAll_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); foreach (ListViewItem item in listUrls.Items) { sb.AppendLine(item.Text); } try { Clipboard.SetText(sb.ToString()); } catch (Exception ex) { CppUtils.CenteredMessageBox(this, ex.Message, Application.ProductName); } }
private void FormPrint_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult.Yes != CppUtils.CenteredMessageBox(this, Properties.Resources.AreYouSureToQuit, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { e.Cancel = true; return; } HashIni ini = Profile.ReadAll(IniFile); Profile.WriteInt(SECTION_OPTION, KEY_WAIT_COUNT, decimal.ToInt32(udWait.Value), ini); if (!Profile.WriteAll(ini, IniFile)) { CppUtils.Alert(Properties.Resources.FAILED_TO_SAVE_INI); } Environment.Exit(0); }
private void btnOK_Click(object sender, EventArgs e) { Int64 fsize = GetCreatingFileSize(); if (fsize < 0) { MessageBox.Show(Properties.Resources.FILESIZE_NOTBE_MINUS, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (fsize > ((Int64)2 * 1024 * 1024 * 1024)) { if (DialogResult.Yes != MessageBox.Show( string.Format(Properties.Resources.ARE_YOU_GOING_TO_CREATE, fsize), Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { return; } } try { if (File.Exists(Filename)) { if (DialogResult.Yes != MessageBox.Show( string.Format(Properties.Resources.ALREADY_EXISTS_DO_YOU_WANT_TO_OVERRIDE, Filename), Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { return; } } FileStream fs = File.Create( Filename, 1, System.IO.FileOptions.RandomAccess); if (chkRandom.Checked) { System.Random r = new Random(); for (long i = 0; i < fsize; ++i) { byte[] b = new byte[1]; r.NextBytes(b); fs.WriteByte(b[0]); } } else if (chkZero.Checked) { for (long i = 0; i < fsize; ++i) { fs.WriteByte(0); } } else { fs.SetLength(fsize); } fs.Close(); CppUtils.CenteredMessageBox("OK", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void ExtractLinks(bool bOnlySelected) { using (new WaitCursor()) { DateTime start = DateTime.Now; while (wbBase.ReadyState < WebBrowserReadyState.Interactive) { Application.DoEvents(); TimeSpan ts = DateTime.Now.Subtract(start); if (ts.Seconds > 10) { switch (CppUtils.CenteredMessageBox(this, Properties.Resources.CancelCompleteCheck, Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)) { case DialogResult.No: start = DateTime.Now; continue; case DialogResult.Cancel: return; } break; } } if (bOnlySelected) { try { IHTMLDocument2 htmlDocument = wbBase.Document.DomDocument as IHTMLDocument2; if (htmlDocument == null) { throw new Exception("No htmlDocument"); } IHTMLSelectionObject currentSelection = htmlDocument.selection; if (currentSelection == null) { throw new Exception("No Selection"); } //if (currentSelection.type == "Text") // throw new Exception("No Links in the selection"); //if(currentSelection.type!="Control") // throw new Exception("No Links in the selection"); IHTMLTxtRange range = currentSelection.createRange() as IHTMLTxtRange; if (range == null) { throw new Exception("No Links in the selection"); } string html = range.htmlText; if (string.IsNullOrEmpty(html)) { throw new Exception("No Links in the selection"); } string[] urls = GetUrlsFromHtml(html, wbBase.Url.AbsoluteUri); foreach (string url in urls) { addToListIfNotEmpty(url); } } catch (Exception ex) { CppUtils.CenteredMessageBox(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { HtmlDocument doc = wbBase.Document; Dictionary <string, int> tagcounter = new Dictionary <string, int>(); // List<string> urls = new List<string>(); foreach (HtmlElement elm in doc.All) { if (elm.TagName == "a" || elm.TagName == "A") { string url = elm.GetAttribute("href"); // urls.Add(url); // listUrls.Items.Add(url); addToListIfNotEmpty(url); } } } } }
private void toolsToolStripMenuItem_DropDownOpening(object sender, EventArgs e) { if (_emptyToolsCount == -1) { _emptyToolsCount = toolsToolStripMenuItem.DropDownItems.Count; } string toolfile = Path.Combine(IniFolder, "ChangeFileNameTools.xml"); List <Miszou.ToolManager.Macro> macroList = new List <Miszou.ToolManager.Macro>(); macroList.Add(new Miszou.ToolManager.Macro(EXTERNAL_MACRO_FILE, "File")); List <Miszou.ToolManager.Macro> folderList = new List <Miszou.ToolManager.Macro>(); ImageList toolImages = new ImageList(); _mTools = null; do { try { _mTools = new Miszou.ToolManager.Tools( toolfile, macroList, folderList, new Miszou.ToolManager.Tools.MacroExpander(ExpandToolMacros), toolImages); } catch (Exception ex) { string message = string.Format(Properties.Resources.FAILED_TO_LOAD_TOOLXML, toolfile, ex.Message); if (CppUtils.CenteredMessageBox( message, Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Error) != DialogResult.OK) { System.Environment.Exit(-1); } } } while (_mTools == null); int startIndex = toolsToolStripMenuItem.DropDownItems.IndexOf(tsmsBeforeTools); // int endIndex = toolsToolStripMenuItem.DropDownItems.IndexOf(tsmsAfterTools); while (toolsToolStripMenuItem.DropDownItems.Count > _emptyToolsCount) { toolsToolStripMenuItem.DropDownItems.RemoveAt(startIndex + 1); } if (_mTools.Count == 0) { ToolStripMenuItem item = new ToolStripMenuItem(); item.Text = Properties.Resources.NO_EXTERNAL_TOOLS_REGISTERED; item.Enabled = false; toolsToolStripMenuItem.DropDownItems.Insert(startIndex + 1, item); } else { _mTools.BuildToolMenu(toolsToolStripMenuItem, startIndex + 1); } }
static int Main(string[] args) { Ambiesoft.CppUtils.AmbSetProcessDPIAware(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SimpleCommandLineParserWritable parser = new SimpleCommandLineParserWritable(args); parser.addOption("rf", ARGUMENT_TYPE.MUST); parser.addOption("rfu", ARGUMENT_TYPE.MUST); parser.addOption("rt", ARGUMENT_TYPE.MUST); parser.addOption("rtu", ARGUMENT_TYPE.MUST); parser.addOption("ie", ARGUMENT_TYPE.MUSTNOT); parser.addOption("ic", ARGUMENT_TYPE.MUSTNOT); parser.addOption("cf", ARGUMENT_TYPE.MUSTNOT); parser.addOption("ncf", ARGUMENT_TYPE.MUSTNOT); parser.addOption("ca", ARGUMENT_TYPE.MUSTNOT); parser.addOption("glob", ARGUMENT_TYPE.MUSTNOT); parser.addOption("h", ARGUMENT_TYPE.MUSTNOT); parser.addOption("?", ARGUMENT_TYPE.MUSTNOT); parser.Parse(); if (parser.getInvalidOptions().Length != 0) { StringBuilder sbMessage = new StringBuilder(); sbMessage.AppendLine(Properties.Resources.INVALID_OPTION); foreach (string s in parser.getInvalidOptions()) { sbMessage.AppendLine(s); } sbMessage.AppendLine(); sbMessage.AppendLine(Properties.Resources.HYPHEN_EXPLANATION); ShowAlert(sbMessage.ToString()); return(1); } if (parser["h"] != null || parser["?"] != null) { ShowHelp(); return(0); } StringBuilder sbCheckArguments = new StringBuilder(); using (var prepareForm = new FormPrepare(parser)) { if (parser["rf"] != null) { sbCheckArguments.Append("rf:"); sbCheckArguments.AppendLine(parser["rf"].ToString()); } if (parser["rfu"] != null) { sbCheckArguments.Append("rfu:"); sbCheckArguments.AppendLine(parser["rfu"].ToString()); } if (parser["rt"] != null) { sbCheckArguments.Append("rt:"); sbCheckArguments.AppendLine(parser["rt"].ToString()); } if (parser["rtu"] != null) { sbCheckArguments.Append("rtu:"); sbCheckArguments.AppendLine(parser["rtu"].ToString()); } if (parser["ie"] != null) { sbCheckArguments.AppendLine("ie"); } if (parser["ic"] != null) { sbCheckArguments.AppendLine("ic"); } if (parser["ca"] != null) { sbCheckArguments.AppendLine("ca"); } if (parser["cf"] != null) { sbCheckArguments.AppendLine("cf"); } if (parser["ncf"] != null) { sbCheckArguments.AppendLine("ncf"); } if (parser["glob"] != null) { sbCheckArguments.AppendLine("glob"); } if (parser["h"] != null) { sbCheckArguments.AppendLine("h"); } if (parser["?"] != null) { sbCheckArguments.AppendLine("?"); } sbCheckArguments.AppendLine(); sbCheckArguments.AppendLine(Properties.Resources.DO_YOU_WANT_TO_CONTINUE); if (GetKeyState(VirtualKeyStates.VK_SHIFT) < 0 || GetKeyState(VirtualKeyStates.VK_CONTROL) < 0) { if (DialogResult.OK != prepareForm.ShowDialog()) { return(0); } } } if (parser["ca"] != null) { // check argument if (DialogResult.Yes != CppUtils.CenteredMessageBox(sbCheckArguments.ToString(), Application.ProductName + " " + "check arg", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { return(0); } } if (parser["rf"] != null && parser["rfu"] != null) { ShowAlert("TODO"); return(1); } if (parser["rt"] != null && parser["rtu"] != null) { ShowAlert("TODO"); return(1); } if (parser["rf"] == null && parser["rfu"] == null) { ShowAlert(Properties.Resources.MUST_SPECIFY_RF_RT); return(1); } if (parser["rt"] == null && parser["rtu"] == null) { ShowAlert(Properties.Resources.MUST_SPECIFY_RF_RT); return(1); } string strRegFind = string.Empty; if (parser["rf"] != null) { strRegFind = parser["rf"].ToString(); } else if (parser["rfu"] != null) { strRegFind = System.Web.HttpUtility.UrlDecode(parser["rfu"].ToString()); } else { throw new Exception(Properties.Resources.UNEXPECTED_ERROR); } string strTarget = string.Empty; if (parser["rt"] != null) { strTarget = parser["rt"].ToString(); } else if (parser["rtu"] != null) { strTarget = System.Web.HttpUtility.UrlDecode(parser["rtu"].ToString()); } else { throw new Exception(Properties.Resources.UNEXPECTED_ERROR); } if (parser.MainargLength == 0) { ShowAlert(Properties.Resources.NO_FILE); return(1); } Regex regf = null; try { if (parser["ic"] != null) { regf = new Regex(strRegFind, RegexOptions.IgnoreCase); } else { regf = new Regex(strRegFind); } } catch (Exception ex) { CppUtils.CenteredMessageBox(ex.Message); return(1); } bool isAlsoExt = null != parser["ie"]; if (parser["cf"] != null && parser["ncf"] != null) { ShowAlert(Properties.Resources.BOTH_CF_NCF_SPECIFIED); return(1); } bool dryrun = parser["ncf"] == null; Dictionary <string, string> targets = new Dictionary <string, string>(); string[] mainArgs = ConstructMainArgs(parser); try { foreach (string orgFullorRelativeFileName in mainArgs) { FileInfo fiorig = new FileInfo(orgFullorRelativeFileName); string orgFileName = getProperName(fiorig, isAlsoExt); string orgFolder = fiorig.DirectoryName; string newFileName = regf.Replace(orgFileName, strTarget); if (!isAlsoExt) { newFileName += fiorig.Extension; } targets.Add(fiorig.FullName, orgFolder + @"\" + newFileName); } if (dryrun) { StringBuilder sbDryAll = new StringBuilder(); StringBuilder sbDryChanging = new StringBuilder(); bool bRenameExists = false; foreach (string org in targets.Keys) { if (org != targets[org]) { bRenameExists = true; string tmp = string.Format("\"{0}\" ->\r\n\"{1}\"", Path.GetFileName(org), Path.GetFileName(targets[org])); sbDryAll.Append(tmp); sbDryChanging.Append(tmp); sbDryChanging.AppendLine(); sbDryChanging.AppendLine(); } else { sbDryAll.AppendFormat("\"{0}\" -> " + Properties.Resources.NO_CHANGE, Path.GetFileName(org), Path.GetFileName(targets[org])); } sbDryAll.AppendLine(); sbDryAll.AppendLine(); } using (FormConfirm form = new FormConfirm()) { form.Text = Application.ProductName + " " + Properties.Resources.CONFIRM; form.lblMessage.Text = !bRenameExists ? Properties.Resources.NO_FILES_TO_RENAME: Properties.Resources.DO_YOU_WANT_TO_PERFORM; form.initialTextAll_ = sbDryAll.ToString(); form.initialTextChanging_ = sbDryChanging.ToString(); form.btnYes.Enabled = bRenameExists; if (DialogResult.Yes != form.ShowDialog()) { return(0); } } } foreach (string org in targets.Keys) { if (org != targets[org]) { if (Directory.Exists(org)) { if (!tryMoveFile(org, targets[org], Directory.Move)) { return(1); } } else if (File.Exists(org)) { if (!tryMoveFile(org, targets[org], File.Move)) { return(1); } } else { CppUtils.Alert(string.Format(Properties.Resources.FILE_NOT_EXIST, org)); } } } return(0); } catch (Exception e) { CppUtils.Fatal(e.Message); return(-1); } }