Пример #1
0
        private void CreateDirectoryIfNecessary(string directoryPath)
        {
            Log.DebugFormat("Creating directory '{0}'...", directoryPath);

            if (!_filesystem.DirectoryExists(directoryPath))
            {
                _filesystem.CreateDirectory(directoryPath);
                Log.InfoFormat("Created directory '{0}'", directoryPath);
            }
        }
Пример #2
0
        public string EnsureExists()
        {
            var appDataDirectory       = _environment.GetAppDataDirectoryPath();
            var toffeeAppDataDirectory = Path.Combine(appDataDirectory, "Toffee");

            if (!_filesystem.DirectoryExists(toffeeAppDataDirectory))
            {
                _filesystem.CreateDirectory(toffeeAppDataDirectory);
            }

            return(toffeeAppDataDirectory);
        }
Пример #3
0
        private bool CreateFile(string content, string directory, string fileName)
        {
            var fullPath = $"{directory}/{fileName}";

            if (_filesystem.FileExists(fullPath))
            {
                Console.WriteLine($"Cannot create file \"{fullPath}\" because it already exists.");
                return(false);
            }

            if (!_filesystem.DirectoryExists(directory))
            {
                Console.WriteLine($"Creating directory \"{directory}\"");
                _filesystem.CreateDirectory(directory);
            }

            Console.WriteLine($"Creating file \"{fullPath}\"");
            _filesystem.WriteFile(fullPath, content);

            return(true);
        }
Пример #4
0
        public (bool isValid, string reason) IsValid(string[] args)
        {
            if (args.Length != 2)
            {
                return(false, "Invalid args. Syntax for the \"restore\" command is: \"restore --dest={path}\"");
            }

            var command = args[0];

            if (command != "restore")
            {
                return(false, "First param was not the \"restore\" command");
            }

            var destinationDirectoryPath = args[1];

            if (string.IsNullOrEmpty(destinationDirectoryPath))
            {
                return(false, "Path to {--dest|-d} directory was not set");
            }

            var destinationDirectoryPathParts = destinationDirectoryPath.Split('=');

            if (destinationDirectoryPathParts.Length != 2)
            {
                return(false, "Path to {--dest|-d} directory was not given correctly. It should be --dest={valid-path} or -d={valid-path}. Remember to wrap the path in double quotes if it contains spaces.");
            }

            if (destinationDirectoryPathParts[0] != "--dest" && destinationDirectoryPathParts[0] != "-d")
            {
                return(false, "Path to {--dest|-d} directory was not given correctly. It should be --dest={valid-path} or -d={valid-path}. Could not find the \"--dest|-d\"-part. Remember to wrap the path in double quotes if it contains spaces.");
            }

            if (!_filesystem.DirectoryExists(destinationDirectoryPathParts[1]))
            {
                return(false, "Path to {--dest|-d} directory does not exist. Remember to wrap the path in double quotes if it contains spaces.");
            }

            return(true, null);
        }
Пример #5
0
        private async Task <string> FindNewFolderName(string parentFolder, string suggested)
        {
            int count = 1;

            string newFullPath = Path.Combine(parentFolder, suggested);

            const string pattern = @"(.+ )\((\d+)\)$";

            while (await _filesystem.DirectoryExists(newFullPath))
            {
                if (Regex.IsMatch(newFullPath, pattern))
                {
                    newFullPath = Regex.Replace(newFullPath, pattern, m => $"{m.Groups[1].Value}({count++})");
                }
                else
                {
                    newFullPath = $"{newFullPath} ({count++})";
                }
            }

            return(Path.GetFileName(newFullPath));
        }
Пример #6
0
        private async Task FolderSelected(object sender, EventArgs <string> e)
        {
            var selectedFolder = e.Value;

            if (selectedFolder.NotEmpty())
            {
                var directoryExists = await _filesystem.DirectoryExists(selectedFolder);

                if (selectedFolder.NotEmpty() && directoryExists)
                {
                    var iRestoreModel = await BuildViewModel(selectedFolder);

                    _view.SetSites(iRestoreModel);
                }
                else
                {
                    _view.DisplayDatabases(new string[] {});
                }

                _view.SetRestoreButtonTitle(Settings.Buttons.Restore);
            }

            _view.SetRestoreButton(null);
        }
Пример #7
0
        public (bool isValid, string reason) IsValid(string[] args)
        {
            if (args.Length != 3)
            {
                return(false, "Invalid args. Syntax for the \"link-from\" command is: \"link-from --src={path} --name={link-name}\"");
            }

            var command = args[0];

            if (command != "link-from")
            {
                return(false, "First param was not the \"link-from\" command");
            }

            var sourceDirectoryPathArg = args[1];

            if (string.IsNullOrEmpty(sourceDirectoryPathArg))
            {
                return(false, "Path to {--src|-s} directory was not set");
            }

            var sourceDirectoryPathParts = sourceDirectoryPathArg.Split('=');

            if (sourceDirectoryPathParts.Length != 2)
            {
                return(false, "Path to {--src|-s} was not given correctly. It should be --src={valid-path} or -s={valid-path}. Remember to wrap the path in double quotes if it contains spaces.");
            }

            if (sourceDirectoryPathParts[0] != "--src" && sourceDirectoryPathParts[0] != "-s")
            {
                return(false, "Path to source directory was not given correctly. It should be --src={valid-path} or -s={valid-path}. Could not find the \"--src|-s\"-part. Remember to wrap the path in double quotes if it contains spaces.");
            }

            var sourceDirectoryPath = sourceDirectoryPathParts[1].Replace('/', '\\');

            if (!_filesystem.DirectoryExists(sourceDirectoryPath))
            {
                return(false, "Path to {--src|-s} directory does not exist. Remember to wrap the path in double quotes if it contains spaces.");
            }

            if (!Path.IsPathRooted(sourceDirectoryPath))
            {
                return(false, "The {--src|-s} directory path must be absolute");
            }

            var linkName = args[2];

            if (string.IsNullOrEmpty(linkName))
            {
                return(false, "Link name was not set");
            }

            var linkNameParts = linkName.Split('=');

            if (linkNameParts.Length != 2)
            {
                return(false, "Link name was not given correctly. It should be --name={link-name} or -n={link-name}. Link name should not contain spaces and be lower case");
            }

            if (linkNameParts[0] != "--name" && linkNameParts[0] != "-n")
            {
                return(false, "Link name was not given correctly. It should be --name={link-name} or -n={link-name}. Could not find the \"--name|-n\"-part");
            }

            if (linkNameParts[1].Contains(" "))
            {
                return(false, "Link name can not contain spaces");
            }

            return(true, null);
        }
Пример #8
0
        public (bool isValid, string reason) IsValid(string[] args)
        {
            if (args.Length != 4)
            {
                return(false, "Invalid args. Syntax for the \"link-to\" command is: \"link-to --dest={path} --link={link-name} --dlls={comma-separated-list-of-dlls-with-no-spaces}\"");
            }

            var command = args[0];

            if (command != "link-to")
            {
                return(false, "First param was not the \"link-to\" command");
            }

            var destinationDirectoryPathArg = args[1];

            if (string.IsNullOrEmpty(destinationDirectoryPathArg))
            {
                return(false, "Path to {--dest|-d} directory was not set");
            }

            var destinationDirectoryPathParts = destinationDirectoryPathArg.Split('=');

            if (destinationDirectoryPathParts.Length != 2)
            {
                return(false, "Path to {--dest|-d} directory was not given correctly. It should be --dest={valid-path} or -d={valid-path}. Remember to wrap the path in double quotes if it contains spaces.");
            }

            if (destinationDirectoryPathParts[0] != "--dest" && destinationDirectoryPathParts[0] != "-d")
            {
                return(false, "Path to {--dest|-d} directory was not given correctly. It should be --dest={valid-path} or -d={valid-path}. Could not find the \"--dest|-d\"-part. Remember to wrap the path in double quotes if it contains spaces.");
            }

            var destinationDirectoryPath = destinationDirectoryPathParts[1].Replace('/', '\\');;

            if (!_filesystem.DirectoryExists(destinationDirectoryPath))
            {
                return(false, "Path to {--dest|-d} directory does not exist. Remember to wrap the path in double quotes if it contains spaces.");
            }

            if (!Path.IsPathRooted(destinationDirectoryPath))
            {
                return(false, "The {--dest|-d} directory path must be absolute");
            }

            var linkNameArg = args[2];

            if (string.IsNullOrEmpty(linkNameArg))
            {
                return(false, "Link name was not set");
            }

            var linkNameParts = linkNameArg.Split('=');

            if (linkNameParts.Length != 2)
            {
                return(false, "Link name was not given correctly. It should be --link={link-name} or -l={link-name}. Link name should not contain spaces and be lower case");
            }

            if (linkNameParts[0] != "--link" && linkNameParts[0] != "-l")
            {
                return(false, "Link name was not given correctly. It should be --link={link-name} or -l={link-name}. Could not find the \"--link|-l\"-part");
            }

            if (linkNameParts[1].Contains(" "))
            {
                return(false, "Link name can not contain spaces");
            }

            var linkName = linkNameParts[1];

            (var foundLink, var link) = _linkRegistryFile.TryGetLink(linkName);

            if (!foundLink)
            {
                return(false, $"The link \"{linkName}\" does not exist in the registry. Did you create it using the \"link-from\" command?");
            }

            var dllsArg = args[3];

            if (string.IsNullOrEmpty(dllsArg))
            {
                return(false, "List of dlls to link was not set. It should be --dlls={comma-separated-list-of-dll-names-with-no-spaces} or -D={dll-names}");
            }

            var dllsParts = dllsArg.Split('=');

            if (dllsParts.Length != 2)
            {
                return(false, "List of dlls to link was not given correctly. It should be dlls={comma-separated-list-of-dll-names-with-no-spaces} or -D={dll-names}");
            }

            if (dllsParts[0] != "--dlls" && dllsParts[0] != "-D")
            {
                return(false, "List of dlls was not given correctly. It should be dlls={comma-separated-list-of-dll-names-with-no-spaces} or -D={dll-names}. Could not find the \"--dlls|-D\"-part");
            }

            if (dllsParts[1].Contains(" "))
            {
                return(false, "List of dlls can not contain spaces");
            }

            var dlls = dllsParts[1].Split(',');

            foreach (var dll in dlls.Where(d => !d.EndsWith("*")))
            {
                var fullDllPath = Path.Combine(link.SourceDirectoryPath, dll);

                var normalizedDllPath = fullDllPath.EndsWith(".dll") ? fullDllPath : $"{fullDllPath}.dll";

                if (!_filesystem.FileExists($"{normalizedDllPath}"))
                {
                    return(false, $"The DLL \"{normalizedDllPath}\" does not exist. The path was constructed by combining the link's ({linkName}) Source Directory ({link.SourceDirectoryPath}) and the entered DLL {dll}. One of these values must be adjusted to make a valid path");
                }
            }

            return(true, null);
        }