Exemplo n.º 1
0
 public bool IsAbsolute(string path)
 {
     return(PathConverter.IsAbsolute(path));
 }
Exemplo n.º 2
0
        public void ExportFile(string projectName, string relativePath, string destination, bool flattenHeirarchy)
        {
            if (PathConverter.IsAbsolute(relativePath))
            {
                relativePath = PathConverter.ToRelative(relativePath);
            }

            destination = PathConverter.ToAbsolute(destination);

            AddImportPattern(projectName, relativePath);

            Console.WriteLine("");
            Console.WriteLine("Exporting files...");
            Console.WriteLine("Project name:");
            Console.WriteLine(projectName);
            Console.WriteLine("Path:");
            Console.WriteLine(relativePath);
            Console.WriteLine("Destination:");
            Console.WriteLine(destination);
            Console.WriteLine("Flatten path:");
            Console.WriteLine(flattenHeirarchy.ToString());
            Console.WriteLine("");
            Console.WriteLine("Files:");

            if (!ImportExists(projectName))
            {
                throw new Exception("Import project '" + projectName + "' not found.");  // TODO: Create custom exception class
            }
            else
            {
                Refresh(projectName);

                var importedProjectDirectory = StagingDirectory
                                               + Path.DirectorySeparatorChar
                                               + projectName;

                Console.WriteLine("");
                Console.WriteLine("Relative path:");
                Console.WriteLine(relativePath);
                Console.WriteLine("");

                foreach (var file in Finder.FindFiles(Environment.CurrentDirectory, relativePath))
                {
                    var fixedPath = PathConverter.ToRelative(relativePath);
                    if (flattenHeirarchy)
                    {
                        fixedPath = Path.GetFileName(relativePath);
                    }

                    Console.WriteLine("");
                    Console.WriteLine("Fixed path:");
                    Console.WriteLine(fixedPath);
                    Console.WriteLine("");

                    var toFile = importedProjectDirectory
                                 + Path.DirectorySeparatorChar
                                 + fixedPath;

                    Console.WriteLine("");
                    Console.WriteLine("Exporting (copying) file:");
                    Console.WriteLine(file);
                    Console.WriteLine("To:");
                    Console.WriteLine(toFile);
                    Console.WriteLine("");

                    DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(toFile));

                    // TODO: Check if need. Git should be keeping backups stored so this backup shouldn't be required.

                    /*if (File.Exists(toFile))
                     * {
                     *  Backup.Backup(toFile);
                     * }*/

                    File.Copy(file, toFile, true);

                    var sourcePath = File.ReadAllText(importedProjectDirectory + Path.DirectorySeparatorChar + "source.txt");

                    Console.WriteLine("Source path:");
                    Console.WriteLine(sourcePath);

                    Git.AddTo(importedProjectDirectory, toFile);

                    // TODO: Find a better way to get the project name
                    var name = Path.GetFileName(WorkingDirectory);

                    Git.CommitTo(importedProjectDirectory, "Exported from '" + name + "' project.");

                    // Get the remote name
                    var remoteName = Path.GetFileName(importedProjectDirectory);

                    // Add the importable project directory as a remote to the original
                    Git.AddRemoteTo(sourcePath, remoteName, importedProjectDirectory);

                    // Pull changes to back to the original project
                    Git.PullTo(sourcePath, remoteName);
                }
            }

            Console.WriteLine("");
            Console.WriteLine("Exporting complete.");
            Console.WriteLine("");
        }