public Addon(string strDir) { // find the right DLL file with the right info to load the assembly (previously declared in info.txt but now automated in order to deprecate info.txt) string[] files = Directory.GetFiles(strDir, "*.dll"); // unblock all dll files, this is potentially required to load the assemblies in the first place foreach (string strFile in files) { FileUnblocker.Unblock(strFile); } // check every file for the presence of AddonHelper foreach (string strFile in files) { Assembly assembly = Assembly.LoadFrom(strFile); Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.BaseType == null) { continue; } if (type.BaseType.FullName == "AddonHelper.Addon") { // found it! Found = true; FullTypeName = type.FullName; PathEntry = strFile; break; } } } // if there's still an info.txt present if (File.Exists(strDir + "\\info.txt")) { // remember if it was enabled before Enabled = new Settings(strDir + "\\info.txt").GetBool("Enabled"); // delete the old deprecated files File.Delete(strDir + "\\info.txt"); if (File.Exists(strDir + "\\info.txt.clean")) { File.Delete(strDir + "\\info.txt.clean"); } } // remember some fun statistics Stats = new Settings(strDir + "/stats.txt"); if (!Stats.Contains("UploadCount")) { Stats.SetInt("UploadCount", 0); Stats.Save(); } this.Path = strDir; }
public void CleanConfigs() { // get all clean filenames (settings.txt.clean and possibly others) string[] cleanConfigs = Directory.GetFiles(".", "*.txt.clean", SearchOption.AllDirectories); foreach (string cleanConfig in cleanConfigs) { // get the live filename string strPathConfig = cleanConfig.Substring(0, cleanConfig.Length - ".clean".Length); // if no live config file yet if (!File.Exists(strPathConfig)) { // copy .txt.clean to .txt! File.Copy(cleanConfig, strPathConfig); } else { // otherwise, let's start comparing them Settings settingsClean = new Settings(cleanConfig); Settings settingsLive = new Settings(strPathConfig); int iUpdates = 0; // for every key in the clean file foreach (KeyValuePair<string, string> entry in settingsClean.Keys) { // if it doesn't exist in the live file if (!settingsLive.Contains(entry.Key)) { // add it to the live file settingsLive.SetString(entry.Key, entry.Value); iUpdates++; } // if it is of name "Version" or "AddonsURL", make sure it's the right updated value if (entry.Key == "Version" || entry.Key == "AddonsURL") { if (settingsLive.GetString(entry.Key) != entry.Value) { settingsLive.SetString(entry.Key, entry.Value); iUpdates++; } } } // eventually save if (iUpdates > 0) { settingsLive.Save(); } } } GC.Collect(); }