예제 #1
0
        private void linkButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(DestinationProjectFolderTextBox.Text))
            {
                DestinationProjectFolderTextBox.BackColor = Color.BlanchedAlmond;
                return;
            }

            if (!Directory.Exists(DestinationProjectFolderTextBox.Text))
            {
                try
                {
                    Directory.CreateDirectory(DestinationProjectFolderTextBox.Text);
                }
                catch (Exception exception)
                {
                    DestinationProjectFolderTextBox.BackColor = Color.BlanchedAlmond;
                    DestinationProjectFolderTextBox.Text      = exception.Message;
                    return;
                }
            }

            ProjectMaker.NewProject(projectsList.ToList(), DestinationProjectFolderTextBox.Text, CreateSubFoldersChk.Checked);
            CheckProjectsList(null, null, true);
            StatusLabel.Text = $"Cloned {projectsList.Count} projects.";
        }
예제 #2
0
 private void linkButton_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(DestinationProjectFolderTextBox.Text) || !Directory.Exists(DestinationProjectFolderTextBox.Text))
     {
         DestinationProjectFolderTextBox.BackColor = Color.BlanchedAlmond;
         return;
     }
     ProjectMaker.NewProject(projectsList.ToList(), DestinationProjectFolderTextBox.Text);
     CheckProjectsList();
 }
예제 #3
0
        public static void ParseCommands(string[] args)
        {
            linkers.Clear();
            // System.Diagnostics.Debugger.Launch(); // to find teh bugs load this in Visual Studio and uncomment the start of this line.
            int argsCount = args.Length;

            if (argsCount == 0)
            {
                Log.WriteLine("No Args given so Help Text Displayed.", ConsoleColor.Red);
                Log.WriteLine();
                Help.Write();
                Finish();
            }

            List <string> argsList = args.Select(a => a.Replace(@"""", "")).ToList();

            if (argsList.Contains("/?"))
            {
                Help.Write();
                Log.WriteLine("User asked For Help. Hope I helped.", ConsoleColor.Green);
                Finish();
            }

            bool doSubDirectories     = argsList.Contains("/s", StringComparer.CurrentCultureIgnoreCase);
            bool createSubDirectories = !argsList.Contains("/nosub", StringComparer.CurrentCultureIgnoreCase);

            Log.WriteToConsole = !argsList.Contains("/stfu", StringComparer.CurrentCultureIgnoreCase);
            NoConfirm          = argsList.Contains("/noconfirm", StringComparer.CurrentCultureIgnoreCase);

            if (argsList.Contains("/abs", StringComparer.CurrentCultureIgnoreCase))
            {
                PathMaker.UseRelativePaths = false;
            }

            string prefixArg = args.FirstOrDefault(arg => arg.StartsWith("/prefix:", StringComparison.OrdinalIgnoreCase));

            if (prefixArg?.Any() ?? false)
            {
                string prefix = prefixArg.Substring(8).Replace("\"", "");
                DestinationProjLinker.LinkPrefix = prefix;
            }


            if (!string.IsNullOrEmpty(argsList[0]))
            {
                if (argsList[0].IsaCsOrVbProjFile())
                {
                    if (argsCount > 1 && args[1].IsaCsOrVbProjFile())
                    {
                        Log.WriteLine("Queueing Code Link from: " + argsList[0], ConsoleColor.Cyan);
                        Log.WriteLine("                     to: " + argsList[1], ConsoleColor.Cyan);
                        Log.WriteLine();
                        linkers.Add(new DestinationProjLinker(argsList[0], argsList[1]));
                    }
                    else
                    {
                        Log.WriteLine("Queueing Code Link to: " + argsList[0] + ". Source TBA.", ConsoleColor.Cyan);
                        linkers.Add(new DestinationProjLinker(argsList[0]));
                    }
                }

                else if (argsList[0].ToLower() == "strip")
                {
                    if (argsCount > 1)
                    {
                        if (args[1].IsaCsOrVbProjFile())
                        {
                            var destinationProjXml = new DestinationProjXml(args[1]);
                            destinationProjXml.ClearOldLinkedCode();
                            destinationProjXml.Save();
                            Finish("Stripped all code from " + args[1]);
                        }

                        else
                        {
                            try
                            {
                                List <string> destProjFiles = GetProjectsFromFolders(argsList[1], doSubDirectories);

                                foreach (string destProjFile in destProjFiles)
                                {
                                    Log.WriteLine("Stripping Code from: " + destProjFile + ". ", ConsoleColor.Yellow);
                                    var destinationProjXml = new DestinationProjXml(destProjFile);
                                    destinationProjXml.ClearOldLinkedCode();
                                    destinationProjXml.Save();
                                }
                            }
                            catch (Exception e)
                            {
                                Crash(e, "Stripping Code from Folder: " + args[1] + " didn't work. Bad name?");
                            }
                            Finish("Stripped all code");
                        }
                    }
                }

                else if (argsList[0].ToLower() == "new")
                {
                    if (argsCount > 2)
                    {
                        if (args[1].IsaCsOrVbProjFile())
                        {
                            string sourcePath = PathMaker.MakeAbsolutePathFromPossibleRelativePathOrDieTrying(null, args[1]);
                            try
                            {
                                ProjectMaker.NewProject(sourcePath, args[2], createSubDirectories);
                            }
                            catch (Exception e)
                            {
                                Crash(e, "Linking " + args[1] + " to " + args[2] + " didn't work. Bad name?");
                            }

                            Finish("Linked " + " from " + args[1] + " to " + args[2]);
                        }

                        else
                        {
                            try
                            {
                                List <string> sourceProjFiles = GetProjectsFromFolders(argsList[1], doSubDirectories);

                                foreach (string sourceProjFile in sourceProjFiles)
                                {
                                    if (sourceProjFile.IsaCsOrVbProjFile())
                                    {
                                        string sourcePath = PathMaker.MakeAbsolutePathFromPossibleRelativePathOrDieTrying(null, sourceProjFile);
                                        try
                                        {
                                            ProjectMaker.NewProject(sourcePath, args[2], createSubDirectories);
                                        }
                                        catch (Exception e)
                                        {
                                            Crash(e, "Linking " + sourceProjFile + " to " + args[2] + " didn't work. Bad name?");
                                        }

                                        Log.WriteLine("Linked " + " from " + sourceProjFile + " to " + args[2], ConsoleColor.Green);
                                    }
                                    else
                                    {
                                        Log.WriteLine("ERROR: " + sourceProjFile + " is not a project file. Cannot Link it.", ConsoleColor.Green);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Crash(e, "Linking Projects from Folder: " + args[1] + " didn't work. Bad name?");
                            }

                            Finish("Linked Projects");
                        }
                    }
                }    // /NewProject

                else // vanilla Link command with a folder
                {
                    try
                    {
                        List <string> destProjFiles = GetProjectsFromFolders(argsList[0], doSubDirectories);

                        foreach (string destProjFile in destProjFiles)
                        {
                            Log.WriteLine("Queueing Code Link to: " + destProjFile + ". Source TBA.", ConsoleColor.Cyan);
                            linkers.Add(new DestinationProjLinker(destProjFile));
                        }
                    }
                    catch (Exception e)
                    {
                        Crash(e, "Queueing Code Link didn't work. Bad file name?");
                    }
                }


                if (!linkers.Any())
                {
                    string errorMessage = "I got nuthin. Your Args made no sense to me." + Environment.NewLine;
                    foreach (string arg in args)
                    {
                        errorMessage += arg + Environment.NewLine;
                    }
                    Crash(errorMessage);
                }


                foreach (DestinationProjLinker destinationProjLinker in linkers)
                {
                    destinationProjLinker.LinkCode();
                }
            }
        }