Esempio n. 1
0
        private void itemExistingFolder_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = sender as ToolStripMenuItem;

            if (item == null)
            {
                return;
            }
            string dir = item.Tag as string;

            if (dir == null)
            {
                // LANG
                CppUtils.Fatal(dir + " is not a directory");
                return;
            }
            else if (!System.IO.Directory.Exists(dir))
            {
                if (DialogResult.Yes != CppUtils.YesOrNo(string.Format(Properties.Resources.DIR_NOT_EXIST_DO_YOU_WANT_TO_REMOVE, dir),
                                                         MessageBoxDefaultButton.Button2))
                {
                    return;
                }
                removeFromDiskDirs(dir);
                return;
            }
            moveToAndClose(dir);
        }
Esempio n. 2
0
 private void goToWebPageToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         Process.Start("https://github.com/erasoni/SendToTools");
     }
     catch (Exception ex)
     {
         CppUtils.Fatal(ex);
     }
 }
Esempio n. 3
0
 private void btnCopy_Click(object sender, EventArgs e)
 {
     try
     {
         Clipboard.SetText(txtName.Text);
     }
     catch (Exception ex)
     {
         CppUtils.Fatal(ex.Message);
     }
 }
Esempio n. 4
0
 private void btnCopyPath_Click(object sender, EventArgs e)
 {
     try
     {
         Clipboard.SetText(this.txtName.Tag.ToString());
     }
     catch (Exception ex)
     {
         CppUtils.Fatal(ex.Message);
     }
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Ambiesoft.CppUtils.AmbSetProcessDPIAware();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (args.Length < 1)
            {
                CppUtils.Alert(Properties.Resources.NO_ARG);
                return;
            }

            try
            {
                string[] lines = System.IO.File.ReadAllLines(args[0]);
                if (lines.Length == 0)
                {
                    CppUtils.Alert(Properties.Resources.NO_FILE_CONTENT);
                    return;
                }

                if (lines[0].Length == 0)
                {
                    CppUtils.Alert(Properties.Resources.EMPTY_FIRST_LINE);
                    return;
                }


                Clipboard.SetText(lines[0]);

                // https://www.flickr.com/photos/thotmeglynn/5161731232/sizes/q/

                NotifyIcon ni = new NotifyIcon();
                ni.BalloonTipTitle = Application.ProductName;
                ni.BalloonTipText  = Properties.Resources.FIRST_LINE_IS_SET_ON_CLIPBOARD;
                ni.Icon            = Properties.Resources.icon;

                ni.Text    = Application.ProductName;
                ni.Visible = true;
                ni.ShowBalloonTip(5 * 1000);

                System.Threading.Thread.Sleep(5 * 1000);
                ni.Dispose();
            }
            catch (Exception ex)
            {
                CppUtils.Fatal(ex);
            }
        }
Esempio n. 6
0
 void ImportDirectory(string dir)
 {
     try
     {
         DirectoryInfo di = new DirectoryInfo(dir);
         foreach (var file in di.GetFiles())
         {
             AddToList(file.FullName);
         }
     }
     catch (Exception ex)
     {
         CppUtils.Fatal(ex);
         Environment.Exit(1);
     }
 }
Esempio n. 7
0
        static internal bool SafeProcessStart(string s, bool showerrorbox)
        {
            try
            {
                System.Diagnostics.Process.Start(s);
                return(true);
            }
            catch (System.Exception e)
            {
                if (showerrorbox)
                {
                    CppUtils.Fatal(e.Message);
                }
            }

            return(false);
        }
Esempio n. 8
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            string fileName  = txtExe.Text;
            string arguments = txtArg.Text;

            // When user tries to launch normal file with arguments,
            // We'll find executable and append original argument after
            // user-input argument.
            if (!string.IsNullOrEmpty(txtArg.Text) && !isExe(txtExe.Text))
            {
                string exe = getExe(txtExe.Text);
                fileName = exe;
                if (!string.IsNullOrEmpty(exe))
                {
                    if (!string.IsNullOrEmpty(arguments))
                    {
                        arguments += " " + Ambiesoft.AmbLib.doubleQuoteIfSpace(txtExe.Text);
                    }
                    else
                    {
                        arguments = Ambiesoft.AmbLib.doubleQuoteIfSpace(txtExe.Text);
                    }
                }
            }
            ProcessStartInfo si = new ProcessStartInfo();

            si.UseShellExecute = true;
            si.FileName        = fileName;
            si.Arguments       = arguments;
            if (chkRunas.Checked)
            {
                si.Verb = "runas";
            }
            si.WorkingDirectory = System.IO.Path.GetDirectoryName(txtExe.Text);

            try
            {
                Process.Start(si);
            }
            catch (Exception ex)
            {
                CppUtils.Fatal(ex);
            }
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            Ambiesoft.CppUtils.AmbSetProcessDPIAware();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (args.Length < 1)
            {
                CppUtils.Alert("No Arguments");
                return;
            }

            try
            {
                dowork(args[0]);
            }
            catch (Exception ex)
            {
                CppUtils.Fatal(ex);
            }
        }
Esempio n. 10
0
        void ImportFromReport(string reportFile)
        {
            if (string.IsNullOrEmpty(reportFile))
            {
                return;
            }

            try
            {
                foreach (string line in File.ReadAllLines(reportFile))
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    AddToList(line);
                }
            }
            catch (Exception ex)
            {
                CppUtils.Fatal(ex);
                Environment.Exit(1);
            }
        }
Esempio n. 11
0
        // [STAThread]
        public static void DllMain()
        {
            if (!preRun())
            {
                return;
            }

            try
            {
                parseCommand(new List <string>(Environment.GetCommandLineArgs()).GetRange(1, Environment.GetCommandLineArgs().Length - 1).ToArray());
            }
            catch (OkException ex)
            {
                CppUtils.Info(ex.Message);
                return;
            }
            catch (Exception ex)
            {
                CppUtils.Fatal(ex.Message);
                return;
            }

            string     livingfile = Path.Combine(ConfigDir, "running");
            FileStream fsRunning  = null;

            // string pidfile = Path.Combine(ConfigDir, "pid");

            // Duplicate instance check only needed if app launch without argument
            // = normal launch
            if (String.IsNullOrEmpty(Program.ApplyInventory))
            {
                try
                {
                    fsRunning = File.Open(livingfile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
                    //FileStream fsPid = File.Open(pidfile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
                    //int pid = Process.GetCurrentProcess().Id;
                    //byte[] b = BitConverter.GetBytes(pid);
                    //fsPid.Write(b, 0, b.Length);
                    //fsPid.Close();
                }
                catch (Exception)
                {
                    // multiple instance
                    try
                    {
                        //FileStream fsPid = File.Open(pidfile, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);
                        //byte[] b = new byte[4];
                        //Array.Clear(b, 0, b.Length);

                        //fsPid.Read(b, 0, 4);
                        //int pid = BitConverter.ToInt32(b, 0);
                        //Process.GetProcessById(pid);

                        // OK, anothor process is running
                        Process[] p = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Application.ExecutablePath));

                        // Activate the first application we find with this name
                        if (p.Length > 0)
                        {
                            BringWindowToFront(p[0].MainWindowHandle);
                            ShowWindow(p[0].MainWindowHandle, ShowWindowEnum.Restore);
                            // MessageBox.Show(p[0].MainWindowHandle.ToString());
                        }
                        else
                        {
                            //string handlefile = Path.Combine(ConfigDir, "winhandle");

                            //using (StreamReader sr = new StreamReader(handlefile))
                            //{
                            //    string s = sr.ReadLine();
                            //    long l;
                            //    long.TryParse(s, out l);
                            //    SetForegroundWindow((IntPtr)l);
                            //}
                        }
                        return;
                    }
                    catch (Exception)
                    {
                        // still failed, uncertain what is going on , then continue.
                    }
                }
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormMain());

            if (fsRunning != null)
            {
                fsRunning.Close();
            }
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            Ambiesoft.CppUtils.AmbSetProcessDPIAware();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                ConvertType ct = ConvertType.Unknown;
                var         p  = new OptionSet()
                {
                    {
                        "t",
                        "treat as text.",
                        v => { ct = ConvertType.Text; }
                    },
                    {
                        "i",
                        "treat as image.",
                        v => { ct = ConvertType.Image; }
                    },
                    {
                        "o",
                        "treat as audio.",
                        v => { ct = ConvertType.Audio; }
                    }
                };


                List <string> extra = p.Parse(args);
                if (extra.Count != 1)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(Properties.Resources.NO_FILE);
                    sb.AppendLine();
                    sb.AppendLine();
                    StringWriter sw = new StringWriter(sb);
                    p.WriteOptionDescriptions(sw);

                    throw new Exception(sb.ToString());
                }

                string file = extra[0];

                //if (args.Length == 1)
                //{
                //    file = args[0];
                //}
                //else if (args.Length == 2)
                //{
                //    if (args[0] == "-t")
                //        ct = ConvertType.Text;
                //    else if (args[0] == "-i")
                //        ct = ConvertType.Image;
                //    else
                //        throw new Exception(string.Format(Properties.Resources.UNKNOWN_OPTION, args[1]));

                //    file = args[1];
                //}
                //else
                //{
                //    throw new Exception(Properties.Resources.TOO_MANY_OPTIONS);
                //}

                if (ct == ConvertType.Unknown)
                {
                    ct = getCorrectTypeFromFile(file);
                }

                switch (ct)
                {
                case ConvertType.Image:
                    Image image = Image.FromFile(file);
                    Clipboard.SetImage(image);
                    break;

                case ConvertType.Text:
                    string all = System.IO.File.ReadAllText(file);
                    Clipboard.SetText(all);
                    break;

                case ConvertType.Audio:
                    throw new Exception("Not implemented");

                case ConvertType.Unknown:
                    throw new Exception(Properties.Resources.UNKNOWN_FILETYPE);
                }

                NotifyIcon ni = new NotifyIcon();
                ni.BalloonTipTitle = Application.ProductName;
                ni.BalloonTipText  = string.Format(Properties.Resources.CLIPBOARDSET,
                                                   ct.ToString());
                ni.Icon = Properties.Resources.icon;

                ni.Text    = Application.ProductName;
                ni.Visible = true;
                ni.ShowBalloonTip(5 * 1000);

                System.Threading.Thread.Sleep(5 * 1000);
                ni.Dispose();
            }
            catch (Exception ex)
            {
                CppUtils.Fatal(ex);
            }
        }
Esempio n. 13
0
        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);
            }
        }
Esempio n. 14
0
        static bool processArgs(string[] args, out string inputFile)
        {
            inputFile = string.Empty;

            // first get lang from command line and set culture
            {
                string lang             = string.Empty;
                var    optionSetForLang = new OptionSet()
                {
                    {
                        "lang=",
                        Properties.Resources.STR_COMMANDLINEHELP_LANG,
                        v =>
                        {
                            lang = v;
                        }
                    },
                };
                optionSetForLang.SafeParse(args);
                if (!string.IsNullOrEmpty(lang))
                {
                    try
                    {
                        CultureInfo ci = new CultureInfo(lang);
                        System.Threading.Thread.CurrentThread.CurrentCulture   = ci;
                        System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, Application.ProductName,
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }

            bool   showHelp    = false;
            bool   showVersion = false;
            string dummy;
            var    optionSet = new OptionSet()
            {
                {
                    "lang=",
                    Properties.Resources.STR_COMMANDLINEHELP_LANG,
                    v =>
                    {
                        dummy = v;
                    }
                },
                {
                    "h|help|?",
                    Properties.Resources.STR_SHOWHELP,
                    v =>
                    {
                        showHelp = true;
                    }
                },
                {
                    "v|version",
                    Properties.Resources.STR_SHOWHELP,
                    v =>
                    {
                        showVersion = true;
                    }
                }
            };
            List <string> extra = optionSet.SafeParse(args);

            if (showHelp)
            {
                StringBuilder sb = new StringBuilder();
                using (StringWriter sw = new StringWriter(sb))
                    optionSet.WriteOptionDescriptions(sw);
                MessageBox.Show(sb.ToString(), Application.ProductName,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }
            if (showVersion)
            {
                MessageBox.Show(
                    string.Format("{0} v{1}",
                                  Application.ProductName, AmbLib.getAssemblyVersion(Assembly.GetExecutingAssembly(), 3)),
                    Application.ProductName,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return(false);
            }
            if (extra.Count > 1)
            {
                foreach (string arg in extra)
                {
                    if (!File.Exists(arg) && !Directory.Exists(arg))
                    {
                        CppUtils.Fatal(string.Format(Properties.Resources.INTPUFILE_NOT_FOUND, arg));
                        continue;
                    }

                    try
                    {
                        Process.Start(Application.ExecutablePath, AmbLib.doubleQuoteIfSpace(arg));
                    }
                    catch (Exception ex)
                    {
                        CppUtils.Alert(ex);
                        continue;
                    }
                }
                return(false);
            }
            else if (extra.Count == 1)
            {
                inputFile = extra[0];
            }
            return(true);
        }
Esempio n. 15
0
        static void Main(string[] argsOriginal)
        {
            Ambiesoft.CppUtils.AmbSetProcessDPIAware();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            if (argsOriginal.Length < 1)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(Properties.Resources.NO_ARGUMENTS);
                sb.AppendLine();
                sb.AppendLine();

                sb.AppendLine(Properties.Resources.HELP);
                CppUtils.Alert(sb.ToString());
                return;
            }

            List <string> args = new List <string>();

            foreach (string arg in argsOriginal)
            {
                if (arg == "-h" || arg == "/h" || arg == "--help")
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine(Properties.Resources.HELP);
                    CppUtils.Alert(sb.ToString());
                    return;
                }
                else if (arg == "/run")
                {
                    run_ = true;
                    continue;
                }
                args.Add(arg);
            }

            if (args.Count > 1)
            {
                StringBuilder sbNotFounds = new StringBuilder();
                for (int i = 0; i < args.Count; ++i)
                {
                    try
                    {
                        if (File.Exists(args[i]) || Directory.Exists(args[i]))
                        {
                            System.Diagnostics.Process.Start(
                                Application.ExecutablePath,
                                (run_ ? "/run ": "") + "\"" + args[i] + "\"");
                        }
                        else
                        {
                            sbNotFounds.AppendLine(args[i]);
                        }
                    }
                    catch (System.Exception e)
                    {
                        CppUtils.Fatal(e.Message);
                    }
                }

                if (sbNotFounds.Length != 0)
                {
                    CppUtils.Alert(Properties.Resources.FOLLOWING_DOESNOT_EXIST + "\r\n\r\n" + sbNotFounds.ToString());
                }
                return;
            }

            string theFileName = args[0].Trim();

            // theFileName = @"C:\Documents and Settings\tt\My Documents\Productivity Distribution, Firm Heterogeneity, and Agglomeration.pdf";
            if (!File.Exists(theFileName) && !Directory.Exists(theFileName))
            {
                CppUtils.Alert(string.Format(Properties.Resources.FILE_NOT_FOUND, theFileName));
                return;
            }

            //System.IO.FileInfo fi = new System.IO.FileInfo(theFileName.Trim());
            //string olddir = fi.Directory.FullName;
            //string oldname = fi.Name;
            //string oldext = fi.Extension;
            bool   bIsFolder = Directory.Exists(theFileName);
            string newName   = bIsFolder ? Path.GetFileName(theFileName) : Path.GetFileNameWithoutExtension(theFileName);

            //if (!string.IsNullOrEmpty(oldext))
            //{
            //    newName = newName.Replace(oldext, "");
            //}

            do
            {
                try
                {
                    FormMain fm = new FormMain();
                    AmbLib.SetFontAll(fm);

                    fm.txtName.Text = newName;
                    fm.txtName.Tag  = theFileName;
                    if (DialogResult.OK != fm.ShowDialog())
                    {
                        return;
                    }

                    //newName = fm.txtName.Text;

                    //if (!RenameIt(olddir, newName, oldname, oldext))
                    //    continue;

                    break;
                }
                catch (Exception e)
                {
                    CppUtils.Alert(e.Message);
                }
            } while (true);
        }
Esempio n. 16
0
        private void moveToAndClose(string path)
        {
            List <Control> csBack = disableAll();

            try
            {
                string srcfilename = this.txtName.Tag.ToString();
                if (File.Exists(srcfilename))
                {
                    System.IO.FileInfo fiorig = new System.IO.FileInfo(srcfilename);

                    string destfilename = txtName.Text + fiorig.Extension;
                    if (-1 != destfilename.IndexOfAny(Program.damemoji.ToCharArray()))
                    {
                        showDamemojiError();
                        return;
                    }
                    string destfullname = System.IO.Path.Combine(path, destfilename);

                    //bool overwrite = false;
                    //if (File.Exists(destfullname))
                    //{
                    //    if (DialogResult.Yes != Ambiesoft.CppUtils.YesOrNo(
                    //        string.Format(Properties.Resources.DESTINATION_EXISTS, destfullname),
                    //        MessageBoxDefaultButton.Button2))
                    //    {
                    //        return;
                    //    }
                    //    overwrite = true;
                    //}

                    // why?
                    //fiorig.CopyTo(destfn, overwrite);
                    //fiorig.Delete();

                    if (0 != Ambiesoft.CppUtils.MoveFile(srcfilename, destfullname))
                    {
                        return;
                    }
                }
                else if (Directory.Exists(srcfilename))
                {
                    DirectoryInfo diorig = new DirectoryInfo(srcfilename);

                    string destfilename = txtName.Text + diorig.Extension;
                    string destfullname = path;

                    if (0 != Ambiesoft.CppUtils.MoveFile(srcfilename, destfullname))
                    {
                        return;
                    }
                }
                this.Close();
            }
            catch (Exception ex)
            {
                CppUtils.Fatal(ex.Message);
            }
            finally
            {
                enableAll(csBack);
            }
        }