////////////////////////////////////////////////////////////////////// // // // GeneralOptions.pas: General Options Dialog // // // // The contents of this file are subject to the Bottled Light // // Public License Version 1.0 (the "License"); you may not use this // // file except in compliance with the License. You may obtain a // // copy of the License at http://www.bottledlight.com/BLPL/ // // // // Software distributed under the License is distributed on an // // "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or // // implied. See the License for the specific language governing // // rights and limitations under the License. // // // // The Original Code is the Mappy VM User Interface, released // // April 1st, 2003. The Initial Developer of the Original Code is // // Bottled Light, Inc. Portions created by Bottled Light, Inc. are // // Copyright (C) 2001-2003 Bottled Light, Inc. All Rights Reserved. // // // // Author(s): // // Michael Noland (joat), michael@bottledlight.com // // // // Changelog: // // 1.0: First public release (April 1st, 2003) // // // // Notes: // // None at present. // // // ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// unit GeneralOptions; ///////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// interface //////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, IniFiles, CheckLst, Registry, Math, CpuObservers, nexus, console; ////////////////////////////////////////////////////////////////////// type TGeneralOptionsDialog = class(TCpuObserver) behaviorGroup: TGroupBox; cShowSplash: TCheckBox; cAutorunROMs: TCheckBox; associationsGroup: TGroupBox; assocs: TCheckListBox; bHelp: TButton; bApply: TButton; languageGroup: TGroupBox; languageSelector: TListBox; lChangeWarning: TLabel; procedure FormCreate(Sender: TObject); procedure FormShow(Sender: TObject); procedure ApplyAssociations(Sender: TObject); procedure ShowHelp(Sender: TObject); procedure ChangeSettings(Sender: TObject); procedure ChangeLanguage(Sender: TObject); public procedure UpdateObserver; override; class function OCaption: string; override; procedure LoadSettings(ini: TIniFile); override; procedure SaveSettings(ini: TIniFile); override; end; ////////////////////////////////////////////////////////////////////// var GeneralOptionsDialog: TGeneralOptionsDialog; // General showSplashScreen: boolean; autorunROMs: boolean; associations: string; runOnce: boolean; languageFile: string; ////////////////////////////////////////////////////////////////////// procedure LoadGeneralOptions(ini: TIniFile); procedure SaveGeneralOptions(ini: TIniFile); ////////////////////////////////////////////////////////////////////// implementation /////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// {$R *.DFM} ////////////////////////////////////////////////////////////////////// // File associations ///////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// procedure ReassertAssociations; var reg: TRegistry; cmd, st: string; begin // Get at the registry reg := TRegistry.Create; reg.RootKey := HKEY_CLASSES_ROOT; // Add the icon for associations if reg.OpenKey('JDEV.AGBBinary\DefaultIcon', true) then begin reg.WriteString('', ParamStr(0) + ',0'); reg.CloseKey; end; if reg.OpenKey('JDEV.AGBSaveState\DefaultIcon', true) then begin reg.WriteString('', ParamStr(0) + ',0'); reg.CloseKey; end; // Add the action for associations if reg.OpenKey('JDEV.AGBBinary\shell\open\command', true) then begin reg.WriteString('', Format('"%s" "%s"', [ParamStr(0), '%1'])); reg.CloseKey; end; if reg.OpenKey('JDEV.AGBSaveState\shell\open\command', true) then begin reg.WriteString('', Format('"%s" "%s"', [ParamStr(0), '%1'])); reg.CloseKey; end; // Set the associations cmd := Trim(associations); while cmd <> '' do begin st := CutLeft(cmd); if st[1] <> '.' then st := '.' + st; if reg.OpenKey(st, true) then begin reg.WriteString('', 'JDEV.AGBBinary'); reg.CloseKey; end; end; // Close the registry reg.Free; end; ////////////////////////////////////////////////////////////////////// // TGeneralOptionsDialog ///////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// procedure TGeneralOptionsDialog.FormCreate(Sender: TObject); begin HelpContext := LinkHelp('general_options.html'); end; ////////////////////////////////////////////////////////////////////// procedure TGeneralOptionsDialog.FormShow(Sender: TObject); var f: TSearchRec; st: string; begin // Build the translation list languageSelector.Clear; languageSelector.Items.Add('[default]'); if FindFirst(ExtractFilePath(ParamStr(0)) + '*.trs', faAnyFile, f) = 0 then repeat st := ExtractFileName(f.Name); Delete(st, Length(st)-3, 4); languageSelector.Items.Add(st); until FindNext(f) <> 0; FindClose(f); // General settings cShowSplash.Checked := showSplashScreen; cAutorunROMS.Checked := autorunROMs; // Load the translation LoadTranslation(self, translation); end; ////////////////////////////////////////////////////////////////////// procedure TGeneralOptionsDialog.ApplyAssociations(Sender: TObject); var cmd: string; begin cmd := ''; if assocs.Checked[0] then cmd := cmd + ' .agb'; if assocs.Checked[1] then cmd := cmd + ' .bin'; if assocs.Checked[2] then cmd := cmd + ' .gba'; if assocs.Checked[3] then cmd := cmd + ' .jst'; if assocs.Checked[4] then cmd := cmd + ' .mb'; if assocs.Checked[5] then cmd := cmd + ' .elf'; associations := Trim(cmd); ReassertAssociations; end; ////////////////////////////////////////////////////////////////////// procedure TGeneralOptionsDialog.ShowHelp(Sender: TObject); begin ShowWebPage(helpFiles.strings[HelpContext-1]); end; ////////////////////////////////////////////////////////////////////// procedure TGeneralOptionsDialog.ChangeSettings(Sender: TObject); begin // General settings showSplashScreen := cShowSplash.Checked; autorunROMs := cAutorunROMS.Checked; end; ////////////////////////////////////////////////////////////////////// // General Preferences ////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// procedure LoadGeneralOptions(ini: TIniFile); begin // Read general settings showSplashScreen := ini.ReadBool('General', 'ShowSplashScren', true); autorunROMs := ini.ReadBool('General', 'Autorun', false); RunOnce := ini.ReadBool('General', 'RunOnce', false); associations := ini.ReadString('General', 'Associations', ''); languageFile := ini.ReadString('General', 'Language', ''); translation.Clear; if FileExists(languageFile) and (Uppercase(languageFile) <> '[DEFAULT]') then translation.LoadFromFile(languageFile) else languageFile := ''; ReassertAssociations; end; ////////////////////////////////////////////////////////////////////// procedure SaveGeneralOptions(ini: TIniFile); begin // Write general settings ini.WriteBool('General', 'ShowSplashScren', showSplashScreen); ini.WriteBool('General', 'Autorun', autorunROMs); ini.WriteBool('General', 'RunOnce', true); ini.WriteString('General', 'Associations', associations); ini.WriteString('General', 'Language', languageFile); end; ////////////////////////////////////////////////////////////////////// procedure TGeneralOptionsDialog.LoadSettings(ini: TIniFile); begin inherited; // end; ////////////////////////////////////////////////////////////////////// class function TGeneralOptionsDialog.OCaption: string; begin Result := 'General Options'; end; ////////////////////////////////////////////////////////////////////// procedure TGeneralOptionsDialog.SaveSettings(ini: TIniFile); begin inherited; // end; ////////////////////////////////////////////////////////////////////// procedure TGeneralOptionsDialog.UpdateObserver; begin // end; ////////////////////////////////////////////////////////////////////// procedure TGeneralOptionsDialog.ChangeLanguage(Sender: TObject); var st: string; begin if languageSelector.ItemIndex > -1 then begin st := ExtractFilePath(ParamStr(0)) + languageSelector.Items[languageSelector.ItemIndex] + '.trs'; if FileExists(st) and (Uppercase(st) <> '[DEFAULT]') then begin languageFile := st; translation.LoadFromFile(st); LoadTranslation(self, translation); ShowMessage(lChangeWarning.Caption); end else languageFile := ''; end; end; ////////////////////////////////////////////////////////////////////// initialization RegisterDialog(TGeneralOptionsDialog); end. //////////////////////////////////////////////////////////////////////