Пример #1
0
        private static void SetupM3InNXMHandler(string nxmIniPath)
        {
            DuplicatingIni ini      = DuplicatingIni.LoadIni(nxmIniPath);
            var            handlers = ini.GetOrAddSection("handlers");
            var            numCurrentHandlersStr = handlers.GetValue("size")?.Value;

            int.TryParse(numCurrentHandlersStr, out var numCurrentHandlers);

            // Find if M3 has been registered for me/me2/me3
            bool updated = false;

            for (int i = 1; i <= numCurrentHandlers; i++)
            {
                var games = handlers.GetValue($@"{i}\games");
                if (games == null)
                {
                    // ???
                    // Is ini configured incorrectly?
                    Log.Warning(@"NXMHandler ini appears to be configured incorrectly");
                }
                else
                {
                    if (games.Value == "other")
                    {
                        Log.Information(@"Updating 'other' in nxmhandler");
                        // We need to update this one
                        handlers.SetSingleEntry($@"{i}\executable", App.ExecutableLocation.Replace("\\", "\\\\"));
                        handlers.SetSingleEntry($@"{i}\arguments", "--nxmlink");
                        updated = true;
                    }
                }
            }

            if (!updated)
            {
                // Add ours
                Log.Warning(@"Adding section 'other' in nxmhandler");
                numCurrentHandlers++;
                handlers.SetSingleEntry($@"size", numCurrentHandlers);
                handlers.SetSingleEntry($@"{numCurrentHandlers}\games", "other");
                handlers.SetSingleEntry($@"{numCurrentHandlers}\executable",
                                        App.ExecutableLocation.Replace("\\", "\\\\"));
                handlers.SetSingleEntry($@"{numCurrentHandlers}\arguments", "--nxmlink");
            }

            File.WriteAllText(nxmIniPath, ini.ToString());
            Log.Information(@"Finished configuring nxmhandler");
            // Register nxm protocol
        }
Пример #2
0
        private void saveData()
        {
            var saveMap = new Dictionary <string, List <IniPropertyMaster> >();

            saveMap[@"BioEngine.ini"] = BioEngineEntries.ToList();
            saveMap[@"BioGame.ini"]   = BioGameEntries.ToList();
            saveMap[@"BioParty.ini"]  = BioPartyEntries.ToList();
            string configFileFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\BioWare\Mass Effect\Config";

            foreach (var kp in saveMap)
            {
                string configFileBeingUpdated = Path.Combine(configFileFolder, kp.Key);
                if (File.Exists(configFileBeingUpdated))
                {
                    Log.Information(@"MEIM: Saving ini file: " + configFileBeingUpdated);

                    //unset readonly
                    File.SetAttributes(configFileBeingUpdated, File.GetAttributes(configFileBeingUpdated) & ~FileAttributes.ReadOnly);

                    DuplicatingIni ini = DuplicatingIni.LoadIni(configFileBeingUpdated);
                    foreach (IniPropertyMaster prop in kp.Value)
                    {
                        string validation = prop.Validate(@"CurrentValue");
                        if (validation == null)
                        {
                            var itemToUpdate = ini.GetValue(prop.SectionName, prop.PropertyName);
                            if (itemToUpdate != null)
                            {
                                itemToUpdate.Value = prop.ValueToWrite;
                            }
                            else
                            {
                                Log.Error($@"Could not find property to update in ini! [{prop.SectionName}] {prop.PropertyName}");
                            }
                        }
                        else
                        {
                            Log.Error($@"Could not save property {prop.FriendlyPropertyName} because {validation}");
                            M3L.ShowDialog(this, M3L.GetString(M3L.string_interp_propertyNotSaved, prop.FriendlyPropertyName, validation), M3L.GetString(M3L.string_errorSavingProperties), MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    Analytics.TrackEvent(@"Saved game config in MEIM");
                    File.WriteAllText(configFileBeingUpdated, ini.ToString());
                    ShowMessage(M3L.GetString(M3L.string_saved));
                }
            }
        }