/// <summary> /// /// </summary> /// <param name="switchableFile"></param> /// <returns></returns> /// <exception cref="System.ArgumentException">NormalFile, CustomFile, TempFile, or RelativeRoot contain /// invalid characters.</exception> /// <exception cref="System.ArgumentNullException">NormalFile, CustomFile, TempFile, or RelativeRoot /// are null.</exception> public static FileSwitcher AsFileSwitcher(this ISwitchableFile switchableFile) { FileSwitcher fileSwitcher = new FileSwitcher(); fileSwitcher.NormalFile = switchableFile.ResolveNormalFile(); fileSwitcher.CustomFile = switchableFile.ResolveCustomFile(); fileSwitcher.TempFile = switchableFile.ResolveTempFile(); fileSwitcher.FileType = switchableFile.FileType; return(fileSwitcher); }
/// <summary> /// Copy constructor /// </summary> /// <param name="other"></param> public SwitchableFile(ISwitchableFile other) { this.Name = other.Name; this.FileType = other.FileType; this.WhetherToSwitchArg = other.WhetherToSwitchArg; this.CustomFileArg = other.CustomFileArg; this.TempFileArg = other.TempFileArg; this.DefaultCustomFile = other.DefaultCustomFile; this.DefaultTempFile = other.DefaultTempFile; this.Switch = other.Switch; this.NormalFile = other.NormalFile; this.CustomFile = other.CustomFile; this.TempFile = other.TempFile; this.RelativeRoot = other.RelativeRoot; }
/// <summary> /// Copy constructor /// </summary> /// <param name="other"></param> public SwitchableFile( ISwitchableFile other ) { this.Name = other.Name; this.FileType = other.FileType; this.WhetherToSwitchArg = other.WhetherToSwitchArg; this.CustomFileArg = other.CustomFileArg; this.TempFileArg = other.TempFileArg; this.DefaultCustomFile = other.DefaultCustomFile; this.DefaultTempFile = other.DefaultTempFile; this.Switch = other.Switch; this.NormalFile = other.NormalFile; this.CustomFile = other.CustomFile; this.TempFile = other.TempFile; this.RelativeRoot = other.RelativeRoot; }
/// <summary> /// Binds switchable file properties to a checkbox using the properties of some other ISwitchableFile. /// </summary> /// <param name="checkbox">The checkbox to bind to.</param> /// <param name="other"></param> public CheckboxSwitchableFile(CheckBox checkbox, ISwitchableFile other) { checkbox.ThrowIfNull("checkbox"); other.ThrowIfNull("other"); m_checkbox = checkbox; m_checkbox.CheckedChanged += (object sender, EventArgs e) => { if (m_checkbox.Enabled) { m_switchIfFilesOk = m_checkbox.Checked; } }; m_checkbox.EnabledChanged += (object sender, EventArgs e) => { if (m_checkbox.Enabled) { m_checkbox.Checked = SwitchIfFilesOk; } else { m_checkbox.Checked = false; } }; AutoRefresh = false; FileType = other.FileType; Name = other.Name; WhetherToSwitchArg = other.WhetherToSwitchArg; CustomFileArg = other.CustomFileArg; TempFileArg = other.TempFileArg; DefaultCustomFile = other.DefaultCustomFile; DefaultTempFile = other.DefaultTempFile; NormalFile = other.NormalFile; CustomFile = other.CustomFile; TempFile = other.TempFile; RelativeRoot = other.RelativeRoot; SwitchIfFilesOk = other.Switch; AutoRefresh = true; Refresh(); }
/// <summary> /// Binds switchable file properties to a checkbox using the properties of some other ISwitchableFile. /// </summary> /// <param name="checkbox">The checkbox to bind to.</param> /// <param name="other"></param> public CheckboxSwitchableFile( CheckBox checkbox, ISwitchableFile other ) { checkbox.ThrowIfNull( "checkbox" ); other.ThrowIfNull( "other" ); m_checkbox = checkbox; m_checkbox.CheckedChanged += ( object sender, EventArgs e ) => { if ( m_checkbox.Enabled ) { m_switchIfFilesOk = m_checkbox.Checked; } }; m_checkbox.EnabledChanged += ( object sender, EventArgs e ) => { if ( m_checkbox.Enabled ) { m_checkbox.Checked = SwitchIfFilesOk; } else { m_checkbox.Checked = false; } }; AutoRefresh = false; FileType = other.FileType; Name = other.Name; WhetherToSwitchArg = other.WhetherToSwitchArg; CustomFileArg = other.CustomFileArg; TempFileArg = other.TempFileArg; DefaultCustomFile = other.DefaultCustomFile; DefaultTempFile = other.DefaultTempFile; NormalFile = other.NormalFile; CustomFile = other.CustomFile; TempFile = other.TempFile; RelativeRoot = other.RelativeRoot; SwitchIfFilesOk = other.Switch; AutoRefresh = true; Refresh(); }
/// <summary> /// Fixes switchable files that are in an inconsistent state. If they are not in an inconsistent state, /// does nothing. /// </summary> /// <param name="switchableFile"></param> /// <param name="wereBroken">Set to true if the files were in an inconsistent state.</param> /// <exception cref="System.IO.IOException">There was an error while fixing the files.</exception> /// <exception cref="System.ArgumentException">NormalFile, CustomFile, or TempFile contain invalid /// characters.</exception> /// <exception cref="System.ArgumentNullException">NormalFile, CustomFile, or TempFile are null.</exception> public static void FixBrokenFilesIfNeeded(this ISwitchableFile switchableFile, out bool wereBroken) { FileSwitcher files = switchableFile.AsFileSwitcher(); files.FixBrokenFiles(out wereBroken); }
/// <summary> /// Fixes switchable files that are in an inconsistent state. If they are not in an inconsistent state, /// does nothing. /// </summary> /// <param name="switchableFile"></param> /// <exception cref="System.IO.IOException">There was an error while fixing the files.</exception> public static void FixBrokenFilesIfNeeded(this ISwitchableFile switchableFile) { bool wasBroken; FixBrokenFilesIfNeeded(switchableFile, out wasBroken); }
/// <summary> /// Resolves TempFile to an absolute path if it is a relative path using RelativeRoot. /// If it is already an absolute path, TempFile is returned. /// </summary> /// <param name="switchableFile"></param> /// <returns></returns> /// <exception cref="System.ArgumentException">TempFile or RelativeRoot contain invalid characters.</exception> /// <exception cref="System.ArgumentNullException">TempFile or RelativeRoot is null.</exception> public static string ResolveTempFile(this ISwitchableFile switchableFile) { return(Utilities.ResolvePossiblyRelativePath(switchableFile.TempFile, switchableFile.RelativeRoot)); }
/// <summary> /// Applies the command-line arguments and saved settings to the form's properties. /// Command-line arguments take precedence, following by saved settings, followed by a default. /// </summary> private void ApplySettingsAndArguments() { Logging.Log.Debug("Applying settings and arguments."); SettingsLoader.ApplySettingStruct(m_parsedArgs.Settings.ClosePopup, m_savedSettings.ClosePopup, null, "Close popup", ( bool closePopup ) => ClosePopup = closePopup, m_launcher.Params.ClosePopup, SensitiveData.None); SettingsLoader.ApplySettingStruct(m_parsedArgs.Settings.LaunchWindowed, m_savedSettings.LaunchWindowed, null, "Launch windowed", ( bool windowed ) => LaunchWindowed = windowed, false, SensitiveData.None); SettingsLoader.ApplySettingStruct(null, m_savedSettings.RememberUsername, null, "Remember username", ( bool remember ) => RememberMe = remember, false, SensitiveData.None); SettingsLoader.ApplySettingClass(m_parsedArgs.Settings.Username, m_savedSettings.Username, null, "Username", ( string user ) => Username = user, "", SensitiveData.Usernames); SettingsLoader.ApplySettingClass(m_parsedArgs.Settings.Password, m_savedSettings.Password, null, "Password", ( string pass ) => Password = pass, "", SensitiveData.Passwords); Func <int, string> validateWindowSize = ( int size ) => { if (size > 0) { return(null); } else { return(string.Format("{0} is not a positive integer.", size)); } }; SettingsLoader.ApplySettingStruct(m_parsedArgs.Settings.GameWindowWidth, m_savedSettings.GameWindowWidth, validateWindowSize, "Starting game window width", ( int width ) => GameWindowStartingWidth = width, DfoLauncher.DefaultGameWindowWidth, SensitiveData.None); SettingsLoader.ApplySettingStruct(m_parsedArgs.Settings.GameWindowHeight, m_savedSettings.GameWindowHeight, validateWindowSize, "Starting game window height", ( int height ) => GameWindowStartingHeight = height, DfoLauncher.DefaultGameWindowHeight, SensitiveData.None); Func <string, string> validatePath = ( string dir ) => { if (Utilities.PathIsValid(dir)) { return(null); } else { return(string.Format("{0} is not a valid path.", dir)); } }; SettingsLoader.ApplySettingClass(m_parsedArgs.Settings.DfoDir, m_savedSettings.DfoDir, validatePath, "DFO directory", ( string dfodir ) => { if (dfodir != null) { DfoDir = dfodir; } }, null, SensitiveData.None); if (DfoDir == null) { try { AutoDetectDfoDir(); } catch (IOException ex) { Logging.Log.ErrorFormat("Could not autodetect the DFO directory. {0} Using {1} as a fallback.", ex.Message, DefaultDfoDir); DfoDir = DefaultDfoDir; } } foreach (string switchableName in m_parsedArgs.Settings.SwitchableFiles.Keys) { ISwitchableFile switchableFromArgs = m_parsedArgs.Settings.SwitchableFiles[switchableName]; bool? switchFromArgs = m_parsedArgs.Settings.SwitchFile[switchableName]; ISwitchableFile switchableFromSettings = m_savedSettings.SwitchableFiles[switchableName]; bool? switchFromSettings = m_savedSettings.SwitchFile[switchableName]; SwitchableFiles[switchableName].RelativeRoot = DfoDir; SettingsLoader.ApplySettingClass(switchableFromArgs.CustomFile, switchableFromSettings.CustomFile, validatePath, string.Format("Custom file for {0}", switchableFromArgs.NormalFile), ( string customFile ) => SwitchableFiles[switchableName].CustomFile = customFile, switchableFromArgs.DefaultCustomFile, SensitiveData.None); SettingsLoader.ApplySettingClass(switchableFromArgs.TempFile, switchableFromSettings.TempFile, validatePath, string.Format("Temp file for {0}", switchableFromArgs.NormalFile), ( string tempFile ) => SwitchableFiles[switchableName].TempFile = tempFile, switchableFromArgs.DefaultTempFile, SensitiveData.None); SettingsLoader.ApplySettingStruct(switchFromArgs, switchFromSettings, null, string.Format("Switch {0}", switchableFromArgs.NormalFile), ( bool switchFile ) => SwitchableFiles[switchableName].SwitchIfFilesOk = switchFile, false, SensitiveData.None); } Logging.Log.Debug("Done applying settings and arguments."); }
public PlainUiSwitchableFile( ISwitchableFile other ) : base(other) { SwitchIfFilesOk = other.Switch; }
public PlainUiSwitchableFile(ISwitchableFile other) : base(other) { SwitchIfFilesOk = other.Switch; }