Beispiel #1
0
        /// <summary>
        /// Process a single .version file
        /// </summary>
        /// <param name="fname"></param>
        /// <returns></returns>
        bool DoProcess(string fname)
        {
            string json = File.ReadAllText(fname);
            var    data = Json.Deserialize(json) as Dictionary <string, object>;

            if (data == null)
            {
                ParseError       = true;
                AddParseErrorMsg = "[InstallValidator] Bad .version file!, " + fname + " is invalid";
                Log.Error("[InstallValidator] Error in Json.Deserialize, file: " + fname);
                return(false);
            }

            foreach (var key in data.Keys)
            {
                if (key == "NAME")
                {
                    ModName = (string)data[key];
                }
                if (key == "INSTALL_LOC" || key.StartsWith("INSTALL_LOC_"))
                {
                    var installLocInfo = new InstallLocInfo(data[key]);
                    ValidateInstallLoc(key, installLocInfo);
                }
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Validate that the specified path, directory & file exist
        /// </summary>
        /// <param name="stanza"></param>
        /// <param name="ili"></param>
        void ValidateInstallLoc(string stanza, InstallLocInfo ili)
        {
            string fullPath = "GameData/" + ili.Path;

            if (ili.Path != null && !Directory.Exists(fullPath))
            {
                ParseError       = true;
                AddParseErrorMsg = ProcessMessage("Path", ili, stanza, DefaultMsg);

                Log.Error("Missing path: " + ili.Path);
                return;
            }
            fullPath += "/" + ili.Directory;
            fullPath.Replace("//", "/");

            if (ili.Directory != null && !Directory.Exists(fullPath))
            {
                ParseError       = true;
                AddParseErrorMsg = ProcessMessage("Directory", ili, stanza, DefaultMsg);

                Log.Error("Missing directory: " + ili.Directory);
                return;
            }
            fullPath += "/" + ili.FileName;
            fullPath.Replace("//", "/");
            if (!File.Exists(fullPath))
            {
                ParseError       = true;
                AddParseErrorMsg = ProcessMessage("File", ili, stanza, DefaultMsg);
                Log.Error("Missing file: " + ili.FileName);
                return;
            }
        }
Beispiel #3
0
        /// <summary>
        /// This processes the message provided in the .version file, doing substitutions as needed
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="ili"></param>
        /// <param name="stanza"></param>
        /// <param name="defaultMsg"></param>
        /// <returns></returns>
        string ProcessMessage(string fieldName, InstallLocInfo ili, string stanza, string defaultMsg)
        {
            string msg;

            if (string.IsNullOrEmpty(ili.Message))
            {
                msg = defaultMsg;
            }
            else
            {
                msg = ili.Message;
            }
            if (ili.Name == null)
            {
                ili.Name = ModName;
            }
            msg = msg.Replace("<MODNAME>", ili.Name);
            msg = msg.Replace("<FILE>", ili.FileName);
            msg = msg.Replace("<DIRECTORY>", ili.Directory);
            msg = msg.Replace("<PATH>", ili.Path);
            msg = msg.Replace("<STANZA>", stanza);
            msg = msg.Replace("<FIELD>", fieldName);
            msg.Replace("//", "/");
            return(msg);
        }
Beispiel #4
0
        /// <summary>
        /// Validate that the specified path, directory & file exist
        /// </summary>
        /// <param name="stanza"></param>
        /// <param name="ili"></param>
        void ValidateInstallLoc(string stanza, InstallLocInfo ili)
        {
            // Use the rootPath to protect against any strange instance where the current directory has been changed
            var rootPath = KSPUtil.ApplicationRootPath.Replace('\\', '/');
            // rootPath already has a trailing slash
            string fullPath = rootPath + "GameData/";

            if (ili.Path != null)
            {
                fullPath += ili.Path;
                fullPath.Replace("//", "/");
                if (!Directory.Exists(fullPath))
                {
                    ParseError       = true;
                    AddParseErrorMsg = ProcessMessage("Path", ili, stanza, DefaultMsg);

                    Log.Error("Missing path: " + ili.Path);
                    Log.Error("Missing fullPath: " + fullPath);
                    return;
                }
            }
            if (ili.Directory != null)
            {
                fullPath += "/" + ili.Directory;
                fullPath.Replace("//", "/");

                if (!Directory.Exists(fullPath))
                {
                    ParseError       = true;
                    AddParseErrorMsg = ProcessMessage("Directory", ili, stanza, DefaultMsg);

                    Log.Error("Missing directory: " + ili.Directory);
                    Log.Error("Missing fullPath: " + fullPath);
                    return;
                }
            }
            if (!ili.FileSpecified)
            {
                return;
            }
            if (String.IsNullOrEmpty(ili.FileName))
            {
                ili.FileName = ili.Name + ".version";
            }
            fullPath += "/" + ili.FileName;
            fullPath.Replace("//", "/");
            if (!File.Exists(fullPath))
            {
                ParseError       = true;
                AddParseErrorMsg = ProcessMessage("File", ili, stanza, DefaultMsg);
                Log.Error("Missing file: " + ili.FileName);
                return;
            }
        }