예제 #1
0
        internal static void Postfix(ConfigFile __instance, BepInPlugin ownerMetadata)
        {
            CachedConfigFile cached = new(__instance, ownerMetadata);

            ConfigFiles.Add(cached);

            ConfigFileCreated?.Invoke(cached);
        }
예제 #2
0
 /// <summary>
 /// Registers a config file
 /// </summary>
 /// <param name="ConfigObject">Config object to register</param>
 public static void RegisterConfigFile(IConfig ConfigObject)
 {
     Contract.Requires <ArgumentNullException>(ConfigObject != null, "ConfigObject");
     if (ConfigFiles.ContainsKey(ConfigObject.Name))
     {
         return;
     }
     ConfigObject.Load();
     ConfigFiles.Add(ConfigObject.Name, ConfigObject);
 }
 /// <summary>
 /// Registers a config file
 /// </summary>
 /// <param name="ConfigObject">Config object to register</param>
 public static void RegisterConfigFile(IConfig ConfigObject)
 {
     if (ConfigObject == null)
     {
         throw new ArgumentNullException("ConfigObject");
     }
     if (ConfigFiles.ContainsKey(ConfigObject.Name))
     {
         return;
     }
     ConfigObject.Load();
     ConfigFiles.Add(ConfigObject.Name, ConfigObject);
 }
예제 #4
0
        /// <summary>
        /// Parses the raw bytes of the .TRP file
        /// </summary>
        private void ParseFile()
        {
            // TODO: Add a warning here
            if (reader.ReadInt32() != magicNumber)
            {
                return;
            }

            // Read out the starting entry count
            reader.BaseStream.Seek(0x10, SeekOrigin.Begin);
            EntryCount = IPAddress.NetworkToHostOrder(reader.ReadInt32());
            Start      = IPAddress.NetworkToHostOrder(reader.ReadInt32());
            reader.BaseStream.Seek(Start, SeekOrigin.Begin);

            long readerOffset = 0;

            fileNameToData = new Dictionary <string, byte[]>();

            for (int i = 0; i < EntryCount; i++)
            {
                // Get our entry info
                string fileName = ReadNullTerminatedString(reader).ToLowerInvariant();
                reader.BaseStream.Seek(Start + (i * 0x40) + 0x20, SeekOrigin.Begin);
                long offset = IPAddress.NetworkToHostOrder(reader.ReadInt64());
                long size   = IPAddress.NetworkToHostOrder(reader.ReadInt64());

                readerOffset = reader.BaseStream.Position + 0x10;

                Console.WriteLine("Processing file [{0}]: {1}", (i + 1), fileName);

                reader.BaseStream.Seek(offset, SeekOrigin.Begin);

                byte[] fileData = reader.ReadBytes(Convert.ToInt32(size));

                fileNameToData.Add(fileName, fileData);

                reader.BaseStream.Seek(readerOffset, SeekOrigin.Begin);
            }

            foreach (KeyValuePair <string, byte[]> z in fileNameToData.Where(x => x.Key.EndsWith(".png")))
            {
                ImageFiles.Add(new PNGFile(z.Value, z.Key));
            }
            foreach (KeyValuePair <string, byte[]> z in fileNameToData.Where(x => x.Key.EndsWith(".sfm") && !x.Key.Contains("tropconf.sfm")))
            {
                ConfigFiles.Add(new SFMFile(z.Value, z.Key, ImageFiles));
            }

            Console.WriteLine("Complete with parsing TRP file...");
        }
예제 #5
0
        /// <summary>
        /// Loads the config files from the ConfigFolder folder
        /// </summary>
        private void LoadConfigFiles()
        {
            // Create directory if it does not exist
            if (!Directory.Exists(ConfigFolder))
            {
                Directory.CreateDirectory(ConfigFolder);
            }

            foreach (var jsonFile in Directory.GetFiles(ConfigFolder, "*.json"))
            {
                var parsedConfigFile = JsonConvert.DeserializeObject <ConfigFile>(File.ReadAllText(jsonFile));
                parsedConfigFile.Name = Path.GetFileNameWithoutExtension(jsonFile);
                ConfigFiles.Add(parsedConfigFile);
            }
        }
예제 #6
0
        public void Check_Calib_Files()
        {
            string c = CalibrationFiles.ToString();
            string d = ConfigFiles.ToString();

            proc(string.Format("adb shell ls {0}", con.Calib()));
            Thread.Sleep(500);
            Regex rx = new Regex("config.ini");

            if (string.IsNullOrEmpty(Output))
            {
                return;
            }

            Match matchCon = rx.Match(Output);

            if (matchCon.Success)
            {
                if (!d.Contains(matchCon.Value))
                {
                    ConfigFiles.Add(matchCon.Value);
                }
            }


            Regex rxDebug       = new Regex("debugConfig.ini");
            Match matchConDebug = rxDebug.Match(Output);

            if (matchConDebug.Success)
            {
                if (!d.Contains(matchConDebug.Value))
                {
                    ConfigFiles.Add(matchConDebug.Value);
                }
            }
            foreach (string cal in con.Get_Cal_Files())
            {
                Regex rx_   = new Regex(cal);
                Match match = rx_.Match(Output);
                if (match.Success)
                {
                    if (!c.Contains(match.Value))
                    {
                        CalibrationFiles.Add(match.Value);
                    }
                }
            }
        }
예제 #7
0
        public void Check_Config_Files_Etc()
        {
            string d = ConfigFiles.ToString();

            proc(string.Format("adb shell ls {0}", con.Get_Etc_Iar_Path()));
            Thread.Sleep(500);
            Regex rx       = new Regex("config.ini");
            Match matchCon = rx.Match(Output);

            if (matchCon.Success)
            {
                if (!d.Contains(matchCon.Value))
                {
                    ConfigFiles.Add(string.Format(@"\etc\iar\{0}", matchCon.Value));
                }
            }
        }
예제 #8
0
        public Mod(string path)
        {
            Path = new DirectoryInfo(path);
            // Files = Path.GetFiles("*", SearchOption.AllDirectories).Select(t => t.GetRelativePathFrom(Path)).ToList();
            Files = Path.GetFiles("*", SearchOption.AllDirectories).ToList();
            foreach (var file in Files)
            {
                // System.Windows.Forms.MessageBox.Show(_file);
                if (file.Name.ToLower() == "mod.json")
                {
                    if (file.Exists)
                    {
                        Manifest      = JsonConvert.DeserializeObject <ModManifest>(file.ReadAllText());
                        Manifest.File = file;

                        /*foreach (var property in GetType().GetProperties())
                         * if (property.GetCustomAttributes(typeof (XmlIgnoreAttribute), false).GetLength(0) == 0)
                         *  property.SetValue(this, property.GetValue(tmp, null), null);*/
                    }
                }
                else if (Stuff.ConfigExtensions.Any(x => file.Extension.ToLower() == x))
                {
                    ConfigFiles.Add(file);
                }
                else if (Stuff.ReadmeExtensions.Any(x => file.Extension.ToLower() == x))
                {
                    ReadmeFiles.Add(file);
                }
                else
                {
                    var _rel = new FileInfo(file.GetRelativePathFrom(Path));
                    if (!Enabled && _rel.Exists && _rel.Length == file.Length)
                    {
                        Enabled = true;                                                        // Todo: Improve detection (maybe check all files and use real checksum?)
                    }
                }
            }
            // ConfigFiles = Files.Where(t => Stuff.ConfigExtensions.Any(t => t.ToLower().EndsWith(".cfg"));
        }
예제 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="dependencies"></param>
        public void SetConfigValue <T>(string key, T value, params IConfigurationDependency[] dependencies) where T : IConvertible
        {
            var fileName = GetFileNameFromDependencies(dependencies);

            // Get file, create it if it doesnt exist yet
            var configFile = ConfigFiles.Find(x => string.Equals(x.Name, fileName, StringComparison.CurrentCultureIgnoreCase));

            if (configFile == null)
            {
                configFile = new ConfigFile
                {
                    Name     = fileName.ToLower(),
                    Sections = new List <ConfigSection>()
                };
                ConfigFiles.Add(configFile);
            }

            var           dependenciesSorted = dependencies.Where(x => x != null).OrderBy(x => x.ConfigOrder);
            ConfigSection curParentSection   = null;

            if (dependencies == null || dependencies.Length == 0)
            {
                ConfigSection section = null;

                if (configFile.Sections.Count == 0)
                {
                    section = new ConfigSection {
                        Id = "global"
                    };
                    configFile.Sections.Add(section);
                }
                else
                {
                    section = configFile.Sections.First();
                }

                SetConfigValue(key, value, section);
                SaveConfigFile(configFile);
            }

            // Find the section
            foreach (var dependency in dependenciesSorted)
            {
                ConfigSection section = null;
                if (curParentSection == null)
                {
                    section = configFile.Sections.Find(x => x.Id == dependency.ConfigId);
                }
                else
                {
                    section = curParentSection.SubSections.Find(x => x.Id == dependency.ConfigId);
                }

                // Create section if it doesnt exist yet
                if (section == null)
                {
                    section = new ConfigSection {
                        Id = dependency.ConfigId
                    };

                    // Add to parent
                    if (curParentSection == null)
                    {
                        configFile.Sections.Add(section);
                    }
                    else
                    {
                        curParentSection.SubSections.Add(section);
                    }
                }

                curParentSection = section;

                // Save the config value
                SetConfigValue(key, value, curParentSection);
            }

            SaveConfigFile(configFile);
        }