Ejemplo n.º 1
0
        public static string BrowseFile(string caption,
                                        FileFilter filters, string initialFile = "", bool includeAllFiles = true)
        {
            if (includeAllFiles)
            {
                filters.Add("All Files", new FileFilterExtensions("*"));
            }

            var filterStr = string.Join("|",
                                        filters.Select(f =>
            {
                var exts = string.Join(";", f.Value.Extensions?.Select(e => $"*.{e}").ToArray());
                return($"{f.Key} ({exts})|{exts}");
            }).ToArray());

            var dlg = new OpenFileDialog()
            {
                Filter   = filterStr,
                Title    = caption,
                FileName = initialFile
            };

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                return(dlg.FileName);
            }
            else
            {
                return("");
            }
        }
Ejemplo n.º 2
0
        static BackupParameters ProcessCommandLine(string[] args)
        {
            BackupParameters param = new BackupParameters();

            int index = 0;

            while (index < args.Length)
            {
                string arg     = args[index];
                string nextArg = index + 1 < args.Length ? args[index + 1] : "";
                switch (arg)
                {
                case "--type":
                    if (nextArg == "Full")
                    {
                        param.type = EBackupType.Full;
                    }
                    else if (nextArg == "Incremental")
                    {
                        param.type = EBackupType.Incremental;
                    }
                    else
                    {
                        throw new ApplicationException($"Unknown backup type '{nextArg}'");
                    }
                    index++;
                    break;

                case "--fileList":
                    if (!File.Exists(nextArg))
                    {
                        throw new ApplicationException($"Can't find include file '{nextArg}'");
                    }
                    else
                    {
                        string[] files = File.ReadAllLines(nextArg);
                        foreach (var f in files)
                        {
                            selectionList.Add(f);
                        }
                    }
                    index++;
                    break;

                case "--excludeList":
                    if (!File.Exists(nextArg))
                    {
                        throw new ApplicationException($"Can't find exclusion file '{nextArg}'");
                    }
                    else
                    {
                        string[] files = File.ReadAllLines(nextArg);
                        foreach (var f in files)
                        {
                            filter.Add(f);
                        }
                    }
                    index++;
                    break;

                case "--lastBackup":
                {
                    DateTime dt;
                    if (DateTime.TryParse(nextArg, out dt))
                    {
                        param.lastBackup = dt;
                    }
                    else
                    {
                        throw new ApplicationException($"Can't understand --lastBackup datetime '{nextArg}'");
                    }
                }
                    index++;
                    break;

                case "--outputPath":
                    param.outputDirectory = nextArg;
                    index++;
                    break;

                case "--backupName":
                    param.backupName = nextArg;
                    index++;
                    break;

                case "--help":
                    System.Console.WriteLine(helpText);
                    System.Environment.Exit(0);
                    break;
                }
                index++;
            }
            System.Console.WriteLine("Backup Starting...");
            System.Console.WriteLine($"Backup Name      {param.backupName}");
            System.Console.WriteLine($"Backup Time      {param.backupTime}");
            System.Console.WriteLine($"Last Backup Time {param.lastBackup}");
            System.Console.WriteLine($"Output Directory {param.outputDirectory}");
            System.Console.WriteLine($"Backup Type      {param.type}");

            return(param);
        }