Пример #1
0
        public bool ProcessCommandLineArgs()
        {
            bool success = true;

            string[] args  = Environment.GetCommandLineArgs();
            Int32    index = 1; //index 0 has the executable name

            while ((args != null) && (index < args.Length))
            {
                string current = args[index];
                switch (current)
                {
                case "/?":
                case "-?":
                    ShowHelp(null);
                    success = false;
                    break;

                case "/f":
                case "-f":
                    ForceSync = true;
                    break;

                case "/w":
                case "-w":
                    ClobberWriteable = true;
                    break;

                case "/a":
                case "-a":
                    AutoStart = true;
                    break;

                case "/v":
                case "-v":
                    ShowWindows = true;
                    break;

                default:
                    if (string.IsNullOrEmpty(SyncFolder) && string.IsNullOrEmpty(Revision))
                    {
                        try
                        {
                            int delim_index = current.IndexOf('@');
                            if (delim_index != -1)
                            {
                                Revision   = current.Substring(delim_index + 1);
                                SyncFolder = current.Substring(0, delim_index);
                            }
                            else
                            {
                                SyncFolder = current;
                            }

                            if (SyncFolder.StartsWith("//"))
                            {
                                ShowHelp("Please use local paths only for the sync.");
                                success = false;
                                break;
                            }

                            SyncFolder = SyncFolder.Replace("/", "\\");

                            if (SyncFolder.StartsWith("\\"))
                            {
                                ShowHelp("Invalid sync path specified.");
                                success = false;
                                break;
                            }
                            else if (SyncFolder.Contains(":"))
                            {
                                ShowHelp("Do not use absolute paths.");
                                success = false;
                                break;
                            }

                            if (SyncFolder == "..")
                            {
                                SyncFolder = Path.GetDirectoryName(Environment.CurrentDirectory);
                            }
                            else if (SyncFolder.StartsWith("..\\"))
                            {
                                string subPart = SyncFolder.Substring(3);
                                SyncFolder = Path.GetDirectoryName(Environment.CurrentDirectory);

                                if (!SyncFolder.EndsWith("\\"))
                                {
                                    SyncFolder += "\\";
                                }

                                SyncFolder += subPart;
                            }
                            else if ((SyncFolder == ".") ||
                                     (SyncFolder == "..."))
                            {
                                SyncFolder = Environment.CurrentDirectory;
                            }
                            else if (SyncFolder.StartsWith(".\\"))
                            {
                                string subPart = SyncFolder.Substring(2);
                                SyncFolder = Environment.CurrentDirectory;

                                if (!SyncFolder.EndsWith("\\"))
                                {
                                    SyncFolder += "\\";
                                }

                                SyncFolder += subPart;
                            }
                            else
                            {
                                string subPart = SyncFolder;
                                SyncFolder = Environment.CurrentDirectory;

                                if (!SyncFolder.EndsWith("\\"))
                                {
                                    SyncFolder += "\\";
                                }

                                SyncFolder += subPart;
                            }

                            if (!string.IsNullOrEmpty(SyncFolder) && !SyncFolder.EndsWith("..."))
                            {
                                if (!SyncFolder.EndsWith("\\"))
                                {
                                    SyncFolder += "\\";
                                }

                                SyncFolder += "...";
                            }

                            SyncFolder = SyncFolder.ToLower().Trim();
                        }
                        catch (Exception exp)
                        {
                            ShowHelp("Arguement - " + current + ". " + exp.Message);
                            success = false;
                        }
                    }
                    else
                    {
                        ShowHelp("Invalid arguement - " + current);
                        success = false;
                    }
                    break;
                }

                if (!success)
                {
                    break;
                }

                index++;
            }

            if (success)
            {
                MainWindow parent = App.Current.MainWindow as MainWindow;
                parent.UpdateSyncDetails(-2, -2);
                GetClientInfo();
            }

            return(success);
        }