Ejemplo 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("");
        }
Ejemplo n.º 2
0
        private void ExecuteAfterBuild()
        {
            if (pm.ProjectPackage.AfterBuild.Length > 0)
            {
                Console.WriteLine("");
                Console.Write("  Executing ");
                ConsoleColorChanger.UseSecondary();
                Console.WriteLine(pm.ProjectPackage.AfterBuild);
                ConsoleColorChanger.UsePrimary();

                Process cmd = new Process();
                cmd.StartInfo.FileName               = "cmd.exe";
                cmd.StartInfo.Arguments              = "/C " + pm.ProjectPackage.AfterBuild;
                cmd.StartInfo.RedirectStandardInput  = true;
                cmd.StartInfo.RedirectStandardOutput = true;
                cmd.StartInfo.CreateNoWindow         = true;
                cmd.StartInfo.UseShellExecute        = false;
                cmd.Start();

                cmd.StandardInput.Flush();
                cmd.StandardInput.Close();
                cmd.WaitForExit();
                ConsoleColorChanger.UseSecondary();
                Console.WriteLine("");
                Console.WriteLine(cmd.StandardOutput.ReadToEnd());
            }
        }
Ejemplo n.º 3
0
        private string GetCodeFor(PackageDependency dep)
        {
            Console.Write("  Building ");
            ConsoleColorChanger.UseSecondary();
            Console.WriteLine(dep.Resource);
            ConsoleColorChanger.UsePrimary();

            var    dirs   = new List <string>();
            string result = GetClientScriptTagStart(dep.Resource);

            if (dep.Type == DependencyType.Package)
            {
                foreach (var src in dep.Sources)
                {
                    if (VerboseLog)
                    {
                        Console.WriteLine("-- Generating code for source: " + src);
                    }
                    dirs.Add(pm.GetDependencyDir(dep));
                }

                var filenames = new List <string>();
                foreach (var dir in dirs)
                {
                    filenames.AddRange(Directory.GetFiles(dir, pm.ProjectPackage.SourceExtensions, SearchOption.AllDirectories));
                }

                foreach (var filename in filenames)
                {
                    if (VerboseLog)
                    {
                        Console.WriteLine("-- Loading code from: " + filename);
                    }
                    result += "\n\n" + File.ReadAllText(filename);
                }
            }
            else
            {
                result += File.ReadAllText(pm.GetDependencyFile(dep));
            }

            return(result + GetClientScriptTagEnd(dep.Resource));
        }
Ejemplo n.º 4
0
        private string GetCodeFor(string[] dirs)
        {
            if (dirs.Length < 1)
            {
                return("");
            }

            string result = "";

            foreach (string dir in dirs)
            {
                string   dirPath = Path.Combine(pm.ProjectDirectory, dir);
                string[] files   = Directory.GetFiles(dirPath, pm.ProjectPackage.SourceExtensions, SearchOption.AllDirectories);
                foreach (string file in files)
                {
                    Console.Write("  Building source ");
                    ConsoleColorChanger.UseSecondary();
                    Console.WriteLine(file);
                    ConsoleColorChanger.UsePrimary();

                    for (int i = 1; i <= 30; ++i)
                    {
                        try {
                            result += "\n\n-- " + file + "\n" + File.ReadAllText(file);
                            break;
                        } catch (IOException) when(i <= 30)
                        {
                            Thread.Sleep(200);
                        }
                    }
                }

                result += GetCodeFor(Directory.GetDirectories(dirPath));
            }

            return(result);
        }
Ejemplo n.º 5
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("");
 }
Ejemplo n.º 6
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;
        }