private static string ExtractInternalFile(string internalResourceName, bool fullname, string destination = null, bool overwrite = false, Stream destStream = null) { MERLog.Information("Extracting file: " + internalResourceName); if (destStream != null || (destination != null && (!File.Exists(destination) || overwrite))) { // Todo: might need adjusted for ME3 using Stream stream = MERUtilities.GetResourceStream(fullname ? internalResourceName : "ME2Randomizer.staticfiles." + internalResourceName); bool close = destStream != null; if (destStream == null) { destStream = new FileStream(destination, FileMode.Create, FileAccess.Write); } stream.CopyTo(destStream); if (close) { stream.Close(); } } else if (destination != null && !overwrite) { MERLog.Warning("File already exists"); } else { MERLog.Warning("Invalid extraction parameters!"); } return(destination); }
public static long GetInstalledRamAmount() { long memKb; GetPhysicallyInstalledSystemMemory(out memKb); if (memKb == 0L) { uint errorcode = GetLastError(); string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message; MERLog.Warning("Failed to get RAM amount. This may indicate a potential (or soon coming) hardware problem. The error message was: " + errorMessage); } return(memKb); }
private static void PerformUACCheck() { bool isAdmin = Utilities.IsAdministrator(); //Check if UAC is off bool uacIsOn = true; string softwareKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; int?value = (int?)Registry.GetValue(softwareKey, "EnableLUA", null); if (value != null) { uacIsOn = value > 0; MERLog.Information("UAC is on: " + uacIsOn); } if (isAdmin && uacIsOn) { MERLog.Warning("This session is running as administrator."); //await this.ShowMessageAsync($"{Utilities.GetAppPrefixedName()} Installer should be run as standard user", $"Running {Utilities.GetAppPrefixedName()} Installer as an administrator will disable drag and drop functionality and may cause issues due to the program running in a different user context. You should restart the application without running it as an administrator unless directed by the developers."); } }
/// <summary> /// Swap the vowels around. Optional hard mode allows swapping 2 consonants to make it extra difficult to read /// </summary> /// <param name="Tlks"></param> public static bool RandomizeVowels(RandomizationOption option) { // Map of what letter maps to what other letter MERLog.Information("Randomizing vowels in words"); var hardMode = option.HasSubOptionSelected(RTexts.SUBOPTIONKEY_VOWELS_HARDMODE); var existingTLK = TLKHandler.GetBuildingTLK(); var skipIDs = existingTLK.StringRefs.Select(x => x.StringID).ToList(); var MERTLKs = TLKHandler.GetMERTLKs(); Dictionary <char, char> vowels = null; List <char> vowelValues = null; bool retryMapping = true; while (retryMapping) { bool failed = false; vowels = GetVowelMap(); vowelValues = vowels.Values.ToList(); int numAttemptsRemaining = 10; foreach (var sourceVowel in vowels.Keys) { var value = vowelValues.RandomElement(); while (hardMode && value == sourceVowel && numAttemptsRemaining > 0) { value = vowelValues.RandomElement(); numAttemptsRemaining--; } if (numAttemptsRemaining == 0 && hardMode && value == sourceVowel) { // This attempt has failed MERLog.Warning(@"Hard mode vowel randomization failed, retrying"); failed = true; break; } vowelValues.Remove(value); // Do not allow reassignment of same vowel Debug.WriteLine($"Vowel Randomizer: {sourceVowel} -> {value}"); vowels[sourceVowel] = value; } if (!failed) { retryMapping = false; } } var consonants = GetConsonantMap(); if (hardMode) { // Swap some consontants around var numConsonantsToRandomize = 2; var consonantValues = consonants.Values.ToList(); while (numConsonantsToRandomize > 0) { var sourceValue = consonantValues.RandomElement(); var value = consonantValues.RandomElement(); while (sourceValue == value) { value = consonantValues.RandomElement(); } consonantValues.Remove(value); // Do not allow reassignment of same vowel consonantValues.Remove(sourceValue); // Do not allow reassignment of same vowel Debug.WriteLine($"Vowel Randomizer Hard Mode: {sourceValue} -> {value}"); consonants[sourceValue] = value; consonants[value] = sourceValue; numConsonantsToRandomize--; } } // Build full translation map (uppercase) var translationMapUC = new[] { vowels, consonants }.SelectMany(dict => dict) .ToDictionary(pair => pair.Key, pair => pair.Value); // Add lowercase translation var lowerCaseMap = translationMapUC.ToDictionary(x => char.ToLowerInvariant(x.Key), x => char.ToLowerInvariant(x.Value)); // Build a full translation var translationMap = new[] { translationMapUC, lowerCaseMap }.SelectMany(dict => dict) .ToDictionary(pair => pair.Key, pair => pair.Value); var nonMERTLKs = TLKHandler.GetAllTLKs().Where(x => !MERTLKs.Contains(x)).ToList(); // MER option.ProgressValue = 0; option.ProgressMax = nonMERTLKs.Sum(x => x.StringRefs.Count(y => y.StringID > 0 && !string.IsNullOrWhiteSpace(y.Data))); option.ProgressMax += MERTLKs.Sum(x => x.StringRefs.Count(y => y.StringID > 0 && !string.IsNullOrWhiteSpace(y.Data))); option.ProgressIndeterminate = false; foreach (var merTLK in MERTLKs) { RandomizeVowelsInternal(merTLK, skipIDs, translationMap, true, option); } // Non MER Parallel.ForEach(nonMERTLKs, tf => { RandomizeVowelsInternal(tf, skipIDs, translationMap, false, option); }); return(true); }