예제 #1
0
        static void Main(string[] allArgs)
        {
            var ap  = new ArgParser();
            var res = ap.Parse(allArgs);

            if (res.Success)
            {
                Addresses.LoadUserAddresses();

                ap.RunDict(new ArgHandler(
                               new AHDict {
                    { "init", new ArgHandler(null, args => {
                            if (!GDMake.IsGlobalInitialized())
                            {
                                GDMake.ShowGlobalNotInitializedError();
                                return;
                            }

                            var project = new Project();

                            project.Name = ap.GetFlagOrArg("name", args, 0);
                            project.Dir  = ap.GetFlagOrArg("dir", args, 1);

                            var res = project.Save(ap.HasFlag("mkdir"), !ap.HasFlag("no-example"));

                            if (res.Failure)
                            {
                                Console.WriteLine($"Error initializing: {(res as ErrorResult<string>).Message}");
                            }
                            else
                            {
                                Console.WriteLine(res.Data);
                            }
                        }) },
예제 #2
0
        public static bool IsGlobalInitialized(bool dontLoadSettings = false)
        {
            if (!Directory.Exists(Path.Join(ExePath, "submodules")))
            {
                return(false);
            }

            if (!Directory.Exists(Path.Join(ExePath, "include")))
            {
                return(false);
            }

            if (!Directory.Exists(Path.Join(ExePath, "src")))
            {
                return(false);
            }

            if (!Directory.Exists(Path.Join(ExePath, "tools")))
            {
                return(false);
            }

            if (!File.Exists(Path.Join(ExePath, "GDMakeSettings.json")))
            {
                return(false);
            }

            if (!dontLoadSettings)
            {
                GDMake.LoadSettings();
            }

            return(true);
        }
예제 #3
0
파일: Project.cs 프로젝트: HJfod/GDMake
        private string GenerateDLLMain()
        {
            var str = DefaultStrings.DllMain;

            str = GDMake.FilterDefaultString(str, "<<?CONSOLE>>", this.Dotfile.ConsoleEnabled);
            str = str.Replace("<<MOD_NAME>>", this.Name);
            str = str.Replace("<<GDMAKE_DIR>>", GDMake.ExePath);

            return(str);
        }
예제 #4
0
        public static void LoadUserAddresses()
        {
            if (!GDMake.IsGlobalInitialized())
            {
                return;
            }

            foreach (var addr in GDMake.SettingsFile.Addresses)
            {
                Names.Add(addr.Item1, addr.Item2);
            }
        }
예제 #5
0
파일: Project.cs 프로젝트: HJfod/GDMake
        private string GenerateCMakeLists(List <string> libs)
        {
            var str = DefaultStrings.CMakeLists;

            str = str.Replace("<<GDMAKE_DIR>>", GDMake.ExePath.Replace("\\", "/"));
            str = str.Replace("<<MOD_NAME>>", this.Name);

            var libstr = "";

            foreach (var lib in libs)
            {
                if (Path.IsPathRooted(lib))
                {
                    libstr += lib + "\n";
                }
                else
                {
                    libstr += $"{GDMake.ExePath.Replace("\\", "/")}/{lib}\n";
                }
            }

            str = str.Replace("<<GDMAKE_LIBS>>", libstr);

            var incpath = "";

            foreach (var inc in GDMake.GetIncludePath())
            {
                incpath += inc + "\n";
            }

            str = str.Replace("<<GDMAKE_HEADERS>>", incpath);

            var srcpath = "";

            foreach (var sub in GDMake.Submodules)
            {
                if (this.Dotfile.Submodules.Contains(sub.Name) && sub.Type == GDMake.Submodule.TSubmoduleType.stIncludeSource)
                {
                    foreach (var src in sub.SourcePaths)
                    {
                        srcpath += src + "\n";
                    }
                }
            }

            str = str.Replace("<<GDMAKE_SOURCES>>", srcpath);

            str = GDMake.FilterDefaultString(str, "<<?GDMAKE_DLLMAIN>>", this.Dotfile.EntryPoint == null);
            str = GDMake.FilterDefaultString(str, "<<?GDMAKE_CONSOLE>>", this.Dotfile.ConsoleEnabled);

            return(str);
        }
예제 #6
0
파일: Project.cs 프로젝트: HJfod/GDMake
        public Result Run()
        {
            Console.WriteLine("Running...");

            var res = GDMake.MoveSharedDLLs();

            if (res.Failure)
            {
                return(res);
            }

            if (!GDMake.GDIsRunning())
            {
                return(new ErrorResult("GD is not running!"));
            }

            res = GDMake.GetBuildDirectory(this.Name);

            if (res.Failure)
            {
                return(res);
            }

            foreach (var resc in Dotfile.Resources)
            {
                try {
                    var target = Path.Join(
                        Path.GetDirectoryName(GDMake.GetGDPath().Data),
                        "Resources",
                        Path.GetFileName(resc)
                        );
                    if (!File.Exists(target))
                    {
                        File.Copy(resc, target);
                    }
                } catch (Exception) { Console.WriteLine($"Error copying {resc}"); }
            }

            res = GDMake.InjectDLL(Path.Join((res as SuccessResult <string>).Data, "res", $"{this.Name}.dll"));

            if (res.Failure)
            {
                return(res);
            }

            Console.WriteLine("Injected DLL!");

            return(new SuccessResult());
        }
예제 #7
0
파일: Project.cs 프로젝트: HJfod/GDMake
        public Result Generate(bool empty = false, bool fullRegen = false, bool verbose = false)
        {
            Console.WriteLine("Generating...");

            var dir = GDMake.MakeBuildDirectory(this.Name, empty);

            this.FullRegen = fullRegen;

            if (dir == null)
            {
                return(new ErrorResult("Unable to create build directory!"));
            }

            if (FullRegen)
            {
                if (Directory.Exists(Path.Join(dir, "src")))
                {
                    GDMake.ForceDeleteDirectory(Path.Join(dir, "src"));
                }

                try { Directory.CreateDirectory(Path.Join(dir, "src")); }
                catch (Exception e) {
                    return(new ErrorResult($"Error: {e.Message}"));
                }
            }

            CopyAllSourceFiles(Path.Join(dir, "src"));
            DeleteSourceFilesNotInDestination(Path.Join(dir, "src"));

            var pre = Preprocessor.PreprocessAllFilesInFolder(this.Dir, Path.Join(dir, "src"), fullRegen, verbose);

            GenerateAndSaveFile(dir, "dllmain.cpp", GenerateDLLMain());
            GenerateAndSaveFile(dir, "debug.h", GenerateDebugHeader(pre));
            GenerateAndSaveFile(dir, "console.cpp", GenerateConsoleSource(pre));
            GenerateAndSaveFile(dir, "hooks.h", GenerateHookHeader(pre));
            GenerateAndSaveFile(dir, "mod.cpp", GenerateModLoad(pre));
            GenerateAndSaveFile(dir, "mod.h", DefaultStrings.ModLoadHeader);
            GenerateAndSaveFile(dir, "CMakeLists.txt", GenerateCMakeLists(this.Dotfile.Libs));

            this.builddir  = dir;
            this.builddlls = this.Dotfile.Dlls;

            return(new SuccessResult());
        }
예제 #8
0
파일: Project.cs 프로젝트: HJfod/GDMake
        public Result Build(string verbosity = "silent", string config = "RelWithDebInfo")
        {
            if (builddir == null)
            {
                return(new ErrorResult("Build directory not set (Make sure to generate first!)"));
            }

            // GDMake.CompileLibs();

            Console.WriteLine("Building DLL...");

            if (Directory.Exists(Path.Join(builddir, "build", config)))
            {
                foreach (var file in Directory.GetFiles(Path.Join(builddir, "build", config), "*.dll"))
                {
                    try { File.Delete(file); } catch (Exception) {}
                }
            }

            var verb = verbosity;

            if (verb == "silent")
            {
                verb = "quiet";
            }
            GDMake.RunBuildBat(Path.Join(builddir).Replace("\\", "/"), this.Name, config, null, verbosity == "silent", verb);

            var resDir = Path.Join(builddir, "res");

            if (Directory.Exists(resDir))
            {
                foreach (var file in Directory.GetFiles(resDir, "*.dll"))
                {
                    try { File.Delete(file); } catch (Exception) {}
                }
            }

            Directory.CreateDirectory(resDir);

            string resPath = null;

            foreach (var file in Directory.GetFiles(
                         Path.Join(builddir, "build", config)
                         ))
            {
                if (file.EndsWith(".dll"))
                {
                    resPath = Path.Join(resDir, Path.GetFileName(file));

                    File.Copy(file, resPath, true);
                }
            }

            if (this.builddlls != null)
            {
                foreach (var dll in this.builddlls)
                {
                    File.Copy(dll, Path.Join(resDir));
                }
            }

            if (resPath == null)
            {
                return(new ErrorResult("Compile error, see message above"));
            }

            Console.WriteLine($"Succesfully built in {resPath}");

            return(new SuccessResult());
        }