Esempio n. 1
0
        private void PrintReadyMessage()
        {
            if (Watchers.Count > 0)
            {
                var sources = String.Join(',', pm.ProjectPackage.Sources.ToArray());
                Console.WriteLine("");
                Console.WriteLine(((new Random()).Next(100) < 50 ? "Nice!" : "Great!") + " Watching for changes:");

                ConsoleColorChanger.UseSecondary();
                Console.Write("  " + pm.ProjectPackageName);
                ConsoleColorChanger.UsePrimary();
                Console.WriteLine(" -> refresh packages");

                if (sources.Length > 0)
                {
                    ConsoleColorChanger.UseSecondary();
                    Console.Write("  " + sources);
                    ConsoleColorChanger.UsePrimary();
                    Console.WriteLine(" -> rebuild modules");
                }

                ConsoleColorChanger.UseSecondary();
                Console.Write("  " + pm.ProjectPackage.Target);
                ConsoleColorChanger.UsePrimary();
                Console.WriteLine(" -> rebuild modules");
            }

            Console.WriteLine("");
            ConsoleColorChanger.UseAccent();
            Console.WriteLine("Now you are free to work with your map directory. Press any key to stop.");
            ConsoleColorChanger.UsePrimary();
            Console.WriteLine("");
        }
Esempio n. 2
0
 private void PrintWatcherEvent(string prefix, string action, string filename = "", string anotherFilename = "")
 {
     if (prefix != "")
     {
         Console.Write("  " + prefix + " ");
     }
     ConsoleColorChanger.UseAccent();
     Console.Write(action + " ");
     ConsoleColorChanger.UsePrimary();
     if (filename != "")
     {
         ConsoleColorChanger.UseSecondary();
         Console.Write(filename + " ");
         ConsoleColorChanger.UsePrimary();
     }
     if (anotherFilename != "")
     {
         Console.Write(" -> ");
         ConsoleColorChanger.UseSecondary();
         Console.Write(anotherFilename + " ");
         ConsoleColorChanger.UsePrimary();
     }
     Console.WriteLine("");
 }
Esempio n. 3
0
        public Application(string projectDir, string[] args, string version)
        {
            Version = version;
            ConsoleColorChanger.SetPrimary(Console.ForegroundColor);
            var noExit = hasArg(args, "--noexit");

            if (args.Length < 1 || noExit)
            {
                Console.WriteLine("Warcraft 3 Lua Package Manager " + Version + " (WLPM) by ScorpioT1000");
                Console.WriteLine("Get more info at: https://github.com/Indaxia/WLPM");
                Console.WriteLine("Arguments:");
                Console.WriteLine("  install <package> [<version>] [file]");
                Console.WriteLine("  - adds a new package or file to your package file and installs dependencies. Omit version to require head revision. To add a file type 'file' as a third parameter");
                Console.WriteLine("  update");
                Console.WriteLine("  - removes any package data and re-downloads it from the internet");
                Console.WriteLine("  build");
                Console.WriteLine("  - builds all downloaded modules and sources into target lua file");
                Console.WriteLine("  update build");
                Console.WriteLine("  - runs 'update' then 'build'");
                Console.WriteLine("  watch");
                Console.WriteLine("  - watches for changes of the sources and target and performs update or build");
                Console.WriteLine("Options:");
                Console.WriteLine("  --detailed");
                Console.WriteLine("  - add this option to get more detailed info about the internal processes");
                Console.WriteLine("");

                if (noExit)
                {
                    ConsoleColorChanger.UseAccent();
                    Console.Error.WriteLine("Press any key to exit.");
                    ConsoleColorChanger.UsePrimary();
                    Console.ReadKey();
                }
                return;
            }

            if (hasArg(args, "--detailed"))
            {
                VerboseLog = true;
            }



            pm = new PackageManager(projectDir, VerboseLog);
            mm = new ModuleManager(pm, VerboseLog, Version);

            for (; RetryAttempt < 3; ++RetryAttempt)
            {
                try {
                    if (hasArg(args, "build"))
                    {
                        pm.RefreshPackages();
                        mm.RebuildModules();
                        return;
                    }
                    else if (hasArg(args, "install"))
                    {
                        if (args.Length < 2)
                        {
                            Console.WriteLine("install format: install url [version]");
                        }
                        else
                        {
                            pm.InstallDependency(args[1], args.Length > 2 ? args[2].Trim() : "*", args.Length > 3 && args[3] == "file");
                        }
                        return;
                    }
                    else if (hasArg(args, "watch"))
                    {
                        pm.RefreshPackages();
                        mm.RebuildModules();
                        WatchForChanges();
                    }
                    else if (hasArg(args, "update"))
                    {
                        pm.RefreshPackages(true);
                        return;
                    }
                    else
                    {
                        Console.WriteLine("Wrong command, execute the program without arguments to get help");
                        return;
                    }
                } catch (Exception e) {
                    ConsoleColorChanger.UseWarning();
                    Console.Error.WriteLine("General Error: " + e.Message);
                    Console.Error.WriteLine("Source: " + e.Source);
                    Console.Error.WriteLine("");
                    Console.Error.WriteLine("Press any key to try again. Press CTRL+C to stop.");
                    ConsoleColorChanger.UsePrimary();
                    Console.ReadKey();
                    pm.Clear();
                    mm.Clear();
                }
                Console.Error.WriteLine("Retry attempt: " + RetryAttempt);
            }
        }
Esempio n. 4
0
        private void _RebuildModules()
        {
            isBusy = true;

            ConsoleColorChanger.UseAccent();
            Console.WriteLine("Rebuilding modules");
            ConsoleColorChanger.UsePrimary();

            string targetFilename = Path.Combine(pm.ProjectDirectory, pm.ProjectPackage.Target);
            string targetOriginal = "";

            for (int i = 1; i <= 30; ++i)
            {
                try {
                    targetOriginal = File.ReadAllText(targetFilename);
                    break;
                } catch (IOException) when(i <= 30)
                {
                    Thread.Sleep(200);
                }
            }


            targetOriginal = RemoveBetween(targetOriginal, ClientScriptStart, ClientScriptEnd);

            string targetHeader = "";
            string targetTop    = "";
            string targetBottom = "\n\n";

            targetHeader += "\n\n-- Warcraft 3 Lua Package Manager " + AppVersion;
            targetHeader += "\n-- Build time: " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss zzz");
            if (pm.ProjectPackage.InsertModuleLoader)
            {
                Console.Write("  Code of ");
                ConsoleColorChanger.UseSecondary();
                Console.Write("WLPM Module Manager");
                ConsoleColorChanger.UsePrimary();
                Console.WriteLine(@" added to the header. To disable, set ""insertModuleLoader"" to false in your " + pm.ProjectPackageName);
                targetHeader += "\n" + GetClientScript();
            }
            else
            {
                Console.Write("Code of ");
                ConsoleColorChanger.UseSecondary();
                Console.Write("WLPM Module Manager");
                ConsoleColorChanger.UsePrimary();
                Console.WriteLine(" is skipped according to your " + pm.ProjectPackageName);
            }
            targetHeader += "\n\n";

            foreach (string index in pm.DependenciesOrderIndex)
            {
                if (!pm.Dependencies.ContainsKey(index))
                {
                    throw new ModuleException("Dependencies collection has no index '" + index + "' but it's stored in indexes. Try to run 'wlpm update'");
                }
                PackageDependency dep  = pm.Dependencies[index];
                string            code = GetCodeFor(dep);
                if (dep.TopOrder)
                {
                    targetTop += "\n\n" + code;
                }
                else
                {
                    targetBottom += "\n\n" + code;
                }
            }

            targetBottom += GetCodeFor(pm.ProjectPackage.Sources.ToArray());

            string target = ClientScriptStart + targetHeader + targetTop + targetBottom + "\n" + ClientScriptEnd + targetOriginal;

            for (int i = 1; i <= 30; ++i)
            {
                try {
                    File.WriteAllText(targetFilename, target);
                    break;
                } catch (IOException) when(i <= 30)
                {
                    Thread.Sleep(200);
                }
            }

            UnsubscribeASAPEvent("ModuleManager.RebuildModules");

            targetLastChange = File.GetLastWriteTimeUtc(targetFilename);

            ExecuteAfterBuild();

            isBusy = false;
        }