コード例 #1
0
ファイル: MainMenu.cs プロジェクト: ShadowsInRain/RogueBackup
        void Help_Execute(string argv, ref Repl repl)
        {
            var name     = argv;
            var specific = null as Command;

            if (!string.IsNullOrEmpty(name))
            {
                specific = Find(name);
                if (specific == null)
                {
                    WriteLine($"Unknown command '{name}'");
                    return;
                }
            }
            if (specific != null)
            {
                var trueName = specific.GetAliases().First();
                if (trueName != name)
                {
                    WriteLine($"'{name}' is an alias for '{trueName}'");
                }
                WriteLine(specific.GetHelp() ?? specific.GetDescription());
            }
            else
            {
                WriteLine(Help_Help());
                WriteLine("All commands:");
                foreach (var command in _commands)
                {
                    var aliasText = string.Join(" or ", command.GetAliases().Select(a => $"'{a}'"));
                    WriteLine($"* {aliasText}: {command.GetDescription()}");
                }
            }
            return;
        }
コード例 #2
0
ファイル: MainMenu.cs プロジェクト: ShadowsInRain/RogueBackup
        void Manual_Execute(string argv, ref Repl repl)
        {
            // TODO consume argv
            // TODO use dedicated Repl to show long text (with prompt to show more)
            const string NN     = "\n\n";
            var          pieces = new string[]
            {
                NN,
                "RogueBackup is low latency backup manager, initially developed to fool videogames with permadeath.",
                "Store and restore files with few keystrokes.",
                "Our main goal is response time, so capabilities are rather barebone.",
                NN,
                "It is possible to manage single file OR entire directory.",
                "To specify which file/directory (aka target) should be archived, RogueBackup requires config file.",
                "Type 'new' to create example config and show it in file explorer.",
                "Open config file with your favorite text editor, edit options to match your case.",
                "When done, type 'profile' to check if your config seems legit.",
                NN,
                "Once configured, manage your backups with commands 'store' and 'restore' or their respective aliases 'save' and 'load'.",
                NN,
                "If you want to manage multiple configurations, path to config file may be passed as command-line argument.",
                "Alternatively, manipulating working directory works as well.",
                NN,
            };

            WriteLine(string.Join(" ", pieces));
        }
コード例 #3
0
ファイル: MainMenu.cs プロジェクト: ShadowsInRain/RogueBackup
        void Store_Execute(string argv, ref Repl repl)
        {
            var suffix  = argv;
            var profile = _service.LoadProfile();
            var name    = _service.GenerateNewArchiveName(profile, suffix);

            WriteLine($"Creating {name}");
            _service.Store(profile, name);
            // TODO remove old files above capacity
            WriteLine("Done");
        }
コード例 #4
0
ファイル: MainMenu.cs プロジェクト: ShadowsInRain/RogueBackup
        void Switch_Execute(string argv, ref Repl repl)
        {
            var path = argv;

            if (!File.Exists(path))
            {
                throw new BoringException("File not found");
            }
            _config.ProfilePath = path;
            Execute(Profile_Command, "brief");
        }
コード例 #5
0
ファイル: MainMenu.cs プロジェクト: ShadowsInRain/RogueBackup
 void Exit_Execute(string argv, ref Repl repl)
 {
     if (!string.IsNullOrEmpty(argv))
     {
         throw new BoringException("Too many arguments.");
     }
     Thread.Sleep(300);
     WriteLine("Stab!");
     Thread.Sleep(300);
     repl = null; // exit
 }
コード例 #6
0
ファイル: MainMenu.cs プロジェクト: ShadowsInRain/RogueBackup
        void Explore_Execute(string argv, ref Repl repl)
        {
            string path;

            switch (argv.ToLower())
            {
            case "target":
            case "t":
                path = _service.LoadProfile().Target;
                break;

            case "storage":
            case "s":
                path = _service.LoadProfile().Storage;
                break;

            case "profile":
            case "p":
                path = _service.ProfilePathFull;
                break;

            case "program":
            case "a":
                path = AppDomain.CurrentDomain.BaseDirectory;
                break;

            case "cwd":
                path = Directory.GetCurrentDirectory();
                break;

            case "":
                throw new BoringException("Too few arguments");

            default:
                throw new BoringException("Unknown option");
            }

            if (File.Exists(path))
            {
                System.Diagnostics.Process.Start("explorer", $"/select,{path}");
            }
            else if (Directory.Exists(path))
            {
                System.Diagnostics.Process.Start("explorer", $"{path}");
            }
            else
            {
                WriteLine($"Path does not exists: {path}");
            }
        }
コード例 #7
0
ファイル: MainMenu.cs プロジェクト: ShadowsInRain/RogueBackup
        void Profile_Execute(string argv, ref Repl repl)
        {
            var brief = false;

            if (argv == "brief")
            {
                brief = true;
            }
            else if (argv != "")
            {
                throw new BoringException("The only argument accepted is 'brief'");
            }

            if (!_service.ProfileExists)
            {
                WriteLine($"Profile does not exists or is not accessible. Create one to proceed.");
                WriteLine($"* Expected path is {_service.ProfilePathFull}");
                return;
            }
            var profile = _service.LoadProfile();
            var issues  = new List <string>();

            profile.Validate(issues.Add);
            var hasIssues = issues.Any();

            WriteLine($"Profile '{profile.Name}' @ {profile.Origin}");
            if (!brief || hasIssues)
            {
                WriteLine($"* Target: {profile.Target}");
                WriteLine($"* Storage: {profile.Storage}");
                WriteLine($"* Capacity: {profile.Capacity}");
                WriteLine($"* Compression: {profile.Compression}");
            }

            if (hasIssues)
            {
                WriteLine("Issues detected:");
                WriteLine(string.Join("\n", issues.Select(i => $"* {i}")));
                WriteLine("Please fix listed issues before proceeding.");
            }
            else if (!brief)
            {
                WriteLine("Ok! (Profile has no obvious issues.)");
            }
        }
コード例 #8
0
ファイル: MainMenu.cs プロジェクト: ShadowsInRain/RogueBackup
        void Restore_Execute(string argv, ref Repl repl)
        {
            var suffix  = argv;
            var profile = _service.LoadProfile();
            var names   = _service.FindRelevantArchivesByName(profile, suffix);

            if (!names.Any())
            {
                WriteLine("Found no matching archives!");
                return;
            }
            var name = names.Last();

            WriteLine($"Restoring {name}");
            // TODO option to clear destination
            _service.Restore(profile, name);
            WriteLine("Done");
        }
コード例 #9
0
ファイル: MainMenu.cs プロジェクト: ShadowsInRain/RogueBackup
        void Find_Execute(string argv, ref Repl repl)
        {
            var suffix  = argv;
            var profile = _service.LoadProfile();
            var names   = _service.FindRelevantArchivesByName(profile, suffix);

            if (names.Any())
            {
                foreach (var name in names)
                {
                    WriteLine(name);
                }
            }
            else
            {
                WriteLine("Nothing found");
            }
        }
コード例 #10
0
ファイル: MainMenu.cs プロジェクト: ShadowsInRain/RogueBackup
        void New_Execute(string argv, ref Repl repl)
        {
            var path = argv;

            if (!string.IsNullOrEmpty(path))
            {
                _config.ProfilePath = path;
            }
            if (_service.ProfileExists)
            {
                WriteLine("Profile exists already.");
                WriteLine("Please delete file manually if you want to reset existing profile.");
            }
            else
            {
                _service.ResetProfile();
                WriteLine("Profile created.");
                WriteLine("Please type 'manual' if you need further instructions.");
            }
            Execute(Explore_Command, "p");
        }