예제 #1
0
        /// <summary>
        /// Deserialize the current config file into our Settings instance
        /// </summary>
        public List <string> ParseToInstance(bool testable = false, List <string> sourceConfig = null)
        {
            List <string> input  = new List <string>();
            SettingsData  _local = testable ? new SettingsData() : Data;

            if (!testable && sourceConfig != null && sourceConfig.Count > 0)
            {
                input = sourceConfig;
            }
            else if (!testable)
            {
                input = File.ReadAllLines(Program.ConfigFile, Encoding.UTF8).ToList();
            }
            else
            {
                input = InstanceToList();
            }

            string lastSection = "";
            object lastSectionObj;

            for (int i = 0; i < input.Count; i++)
            {// iterate through the .ini by parsing lines
                string[] parsedSection = input[i].Split(new char[] { '[', ']' }, 3);
                lastSection = parsedSection.Length > 1 ? parsedSection[1] : lastSection;
                if (!testable)
                {
                    lastSectionObj = Data.GetType().GetProperty(lastSection).GetValue(Data, null);
                }
                else
                {
                    lastSectionObj = _local.GetType().GetProperty(lastSection).GetValue(_local, null);
                }
                string[] item = input[i].Split(new char[] { '=' }, 2);

                if (item.Length == 2)
                {// make sure to validate all mutable inputs parsed from the config file
                    if (item[0] == "GameProcessAffinity" &&
                        SettingsData.ValidateProcessAffinity(item[1], out long _affinity))
                    {
                        lastSectionObj.GetType().GetProperty(item[0]).SetValue(lastSectionObj, _affinity);
                    }
                    else if (item[0] == "GameProcessPriority" &&
                             SettingsData.ValidateProcessPriority(item[1], out ProcessPriorityClass _priority))
                    {
                        lastSectionObj.GetType().GetProperty(item[0]).SetValue(lastSectionObj, _priority);
                    }
                    else if (item[0] == "ReleaseVersion") /* IMMUTABLE */ } {
예제 #2
0
 public Settings(bool testable = false)
 {
     Data = new SettingsData();
     if (!testable && !CheckINI())
     {
         ProcessUtils.Logger("WARNING", "Config file partially invalid or doesn't exist, re-stubbing...");
         if (!MigrateLegacyConfig())
         {// rebuild from scratch if migrate fails
             CreateINIFromInstance();
             PathChooser();
         }
     }
     else if (!testable)
     {
         ParseToInstance();
     }
 }
예제 #3
0
        public ProcessLauncher(string procPath, string procArgs, // required
                               string avoidProcName = "", int delayTime     = 0, bool elevate = false,
                               int avoidPID         = 0, string monitorName = "")
        {
            ProcWrapper   = new ProcessWrapper();
            ExecPath      = procPath;
            ExecArgs      = procArgs;
            AvoidProcName = avoidProcName;
            Delay         = delayTime;
            Elevated      = elevate;
            MonitorName   = monitorName;
            AvoidPID      = avoidPID;

            // construct and save our ProcessWrapper
            if (SettingsData.ValidatePath(ExecPath) ||
                SettingsData.ValidateURI(ExecPath))
            {
                Process _procObj = new Process();
                _procObj.StartInfo.UseShellExecute = true;
                _procObj.StartInfo.FileName        = ExecPath;
                _procObj.StartInfo.Arguments       = ExecArgs;
                if (!SettingsData.ValidateURI(ExecPath))
                {
                    _procObj.StartInfo.WorkingDirectory = Directory.GetParent(ExecPath).ToString();
                }
                if (Elevated)
                {
                    _procObj.StartInfo.Verb = "runas";
                }
                // bind our process wrapper
                ProcWrapper = new ProcessWrapper(_procObj,
                                                 avoidPID: AvoidPID,
                                                 altName: MonitorName,
                                                 avoidProcName: AvoidProcName
                                                 );
            }
        }