Beispiel #1
0
        public static (bool status, string desc) Core(string invokePath, InvokeMethod method, string parameter)
        {
            var gamePath = Config.Read()["GamePath"];

            //decide using internal script or external script
            if (File.Exists(new FilePathBuilder(invokePath).Enter("internal.script").Path))
            {
                //use internal script
                //read file
                var fs   = new StreamReader(new FilePathBuilder(invokePath).Enter("internal.script").Path, Encoding.UTF8);
                var data = fs.ReadToEnd();
                fs.Close();
                fs.Dispose();

                try {
                    return(InternalInvoker(method, (PackageType)Enum.Parse(typeof(PackageType), data), gamePath, invokePath, parameter));
                } catch (Exception) {
                    return(false, I18N.Core("ScriptInvoker_IllegalInternalFlagFileContent"));
                }
            }
            else
            {
                //use external script
                var folder_build = new FilePathBuilder(invokePath, Information.OS);
                folder_build.Enter("setup.cs");
                var script_file = folder_build.Path;
                folder_build.Backtracking();
                folder_build.Enter("setup.dll");
                var dll_file = folder_build.Path;

                if (!File.Exists(script_file))
                {
                    return(false, I18N.Core("ScriptInvoker_NoScriptFile"));
                }

                if (!File.Exists(dll_file))
                {
                    //try compile
                    var test = CompileScript(script_file, dll_file);
                    if (!test.status)
                    {
                        return(false, I18N.Core("ScriptInvoker_CompileError", test.desc));                //todo: translation
                    }
                }

                return(RealInvoker(dll_file, method, gamePath, invokePath, parameter));
            }
        }
Beispiel #2
0
        public static (bool status, string desc) Deploy(string gamePath, string currentPath, string parameter)
        {
            try {
                var _gamePath    = new FilePathBuilder(gamePath, Information.OS);
                var _currentPath = new FilePathBuilder(currentPath);

                var cache_file = _currentPath.Enter("deploy.cfg").Path;
                _currentPath.Backtracking();
                var local_map_file    = _currentPath.Enter("MapNameInPackage.nmo").Path;
                var target_map_folder = _gamePath.Enter("3D Entities").Enter("Level").Path;

                //restore old
                var deploy_cache = ScriptCommon.ReadDeploy(cache_file);
                if (deploy_cache != "")
                {
                    var old_level       = int.Parse(deploy_cache);
                    var target_old_file = new FilePathBuilder(target_map_folder).Enter($"Level_{(old_level < 10 ? "0" : "")}{deploy_cache}.NMO").Path;
                    ScriptCommon.RemoveWithRestore(target_old_file);
                }
                ScriptCommon.RecordDeploy(cache_file, "");

                //deploy new
                _gamePath    = new FilePathBuilder(gamePath);
                _currentPath = new FilePathBuilder(currentPath);

                if (parameter == "")
                {
                    return(true, "");
                }
                var level = int.Parse(parameter);
                if (!(level >= 1 && level <= 15))
                {
                    return(false, "Illegal parameter range");
                }
                var target_file = new FilePathBuilder(target_map_folder).Enter($"Level_{(level < 10 ? "0" : "")}{parameter}.NMO").Path;
                ScriptCommon.CopyWithBackups(target_file, local_map_file);
                ScriptCommon.RecordDeploy(cache_file, level.ToString());
            } catch (Exception e) {
                return(false, "Runtime error:" + Environment.NewLine + e.Message);
            }
            return(true, "");
        }
Beispiel #3
0
        public static (bool status, string desc) Remove(string gamePath, string currentPath)
        {
            try {
                var _gamePath    = new FilePathBuilder(gamePath).Enter("Sounds");
                var _currentPath = new FilePathBuilder(currentPath);

                foreach (var item in file_list)
                {
                    if (File.Exists(_currentPath.Enter(item).Path))
                    {
                        ScriptCommon.RemoveWithRestore(_gamePath.Enter(item).Path);
                        _gamePath.Backtracking();
                    }
                    _currentPath.Backtracking();
                }
            } catch (Exception e) {
                return(false, "Runtime error:" + Environment.NewLine + e.Message);
            }
            return(true, "");
        }
Beispiel #4
0
        public static (bool status, string desc) Deploy(string gamePath, string currentPath, string parameter)
        {
            try {
                var _gamePath    = new FilePathBuilder(gamePath, Information.OS);
                var _currentPath = new FilePathBuilder(currentPath);

                var cache_file = _currentPath.Enter("deploy.cfg").Path;
                _currentPath.Backtracking();
                var local_file_folder = _currentPath.Path;
                var target_folder     = _gamePath.Enter("Textures").Enter("Sky").Path;

                //restore old
                var deploy_cache = ScriptCommon.ReadDeploy(cache_file);
                if (deploy_cache != "")
                {
                    var target_old_file = new FilePathBuilder(target_folder).Enter($"Sky_{deploy_cache}").Path;
                    ScriptCommon.RemoveWithRestore(target_old_file + "_Back.BMP");
                    ScriptCommon.RemoveWithRestore(target_old_file + "_Down.BMP");
                    ScriptCommon.RemoveWithRestore(target_old_file + "_Front.BMP");
                    ScriptCommon.RemoveWithRestore(target_old_file + "_Left.BMP");
                    ScriptCommon.RemoveWithRestore(target_old_file + "_Right.BMP");
                }
                ScriptCommon.RecordDeploy(cache_file, "");

                //deploy new
                _gamePath    = new FilePathBuilder(gamePath);
                _currentPath = new FilePathBuilder(currentPath);

                if (parameter == "")
                {
                    return(true, "");
                }
                var sky      = "A";
                var sp_param = parameter.Split('_');
                if (sp_param[0] == "level")
                {
                    var level = int.Parse(sp_param[1]);
                    if (!(level >= 1 && level <= 15))
                    {
                        return(false, "Illegal parameter range");
                    }
                    sky = level_dict[level];
                }
                else if (sp_param[0] == "sky")
                {
                    sky = sp_param[1].ToUpper();
                }
                else
                {
                    return(false, "Illegal formation");
                }

                if (!legal_character_dict.Contains(sky))
                {
                    return(false, "Illegal formation");
                }


                var target_file = new FilePathBuilder(target_folder).Enter($"Sky_{sky}").Path;
                ScriptCommon.CopyWithBackups(target_file + "_Back.BMP", new FilePathBuilder(local_file_folder).Enter("back.bmp").Path);
                ScriptCommon.CopyWithBackups(target_file + "_Down.BMP", new FilePathBuilder(local_file_folder).Enter("down.bmp").Path);
                ScriptCommon.CopyWithBackups(target_file + "_Front.BMP", new FilePathBuilder(local_file_folder).Enter("front.bmp").Path);
                ScriptCommon.CopyWithBackups(target_file + "_Left.BMP", new FilePathBuilder(local_file_folder).Enter("left.bmp").Path);
                ScriptCommon.CopyWithBackups(target_file + "_Right.BMP", new FilePathBuilder(local_file_folder).Enter("right.bmp").Path);

                ScriptCommon.RecordDeploy(cache_file, sky);
            } catch (Exception e) {
                return(false, "Runtime error:" + Environment.NewLine + e.Message);
            }
            return(true, "");
        }
Beispiel #5
0
        public static (bool status, string desc) Deploy(string gamePath, string currentPath, string parameter)
        {
            try {
                var _gamePath    = new FilePathBuilder(gamePath, Information.OS);
                var _currentPath = new FilePathBuilder(currentPath);

                var cache_file = _currentPath.Enter("deploy.cfg").Path;
                _currentPath.Backtracking();
                var local_file_folder = _currentPath.Path;
                var target_folder     = _gamePath.Enter("Sounds").Path;

                //restore old
                var deploy_cache = ScriptCommon.ReadDeploy(cache_file);
                if (deploy_cache != "")
                {
                    var target_old_file = new FilePathBuilder(target_folder).Enter($"Music_Theme_{deploy_cache}").Path;
                    ScriptCommon.RemoveWithRestore(target_old_file + "_1.wav");
                    ScriptCommon.RemoveWithRestore(target_old_file + "_2.wav");
                    ScriptCommon.RemoveWithRestore(target_old_file + "_3.wav");
                }
                ScriptCommon.RecordDeploy(cache_file, "");

                //deploy new
                _gamePath    = new FilePathBuilder(gamePath);
                _currentPath = new FilePathBuilder(currentPath);

                if (parameter == "")
                {
                    return(true, "");
                }
                var theme    = "1";
                var sp_param = parameter.Split('_');
                if (sp_param[0] == "level")
                {
                    var level = int.Parse(sp_param[1]);
                    if (!(level >= 1 && level <= 15))
                    {
                        return(false, "Illegal parameter range");
                    }
                    theme = level_dict[level];
                }
                else if (sp_param[0] == "theme")
                {
                    theme = sp_param[1];
                }
                else
                {
                    return(false, "Illegal formation");
                }

                if (!legal_character_dict.Contains(theme))
                {
                    return(false, "Illegal formation");
                }


                var target_file = new FilePathBuilder(target_folder).Enter($"Music_Theme_{theme}").Path;
                ScriptCommon.CopyWithBackups(target_file + "_1.wav", new FilePathBuilder(local_file_folder).Enter("1.wav").Path);
                ScriptCommon.CopyWithBackups(target_file + "_2.wav", new FilePathBuilder(local_file_folder).Enter("2.wav").Path);
                ScriptCommon.CopyWithBackups(target_file + "_3.wav", new FilePathBuilder(local_file_folder).Enter("3.wav").Path);

                ScriptCommon.RecordDeploy(cache_file, theme);
            } catch (Exception e) {
                return(false, "Runtime error:" + Environment.NewLine + e.Message);
            }
            return(true, "");
        }