2007-04-22 03:23:25 +02:00
// Copyright (c) 2005-2007, Rodrigo Braz Monteiro
2006-01-16 22:02:54 +01:00
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
////////////
// Includes
# include <string>
# include <wx/filename.h>
# include <fstream>
# include <wx/intl.h>
2006-02-21 08:21:07 +01:00
# include <wx/settings.h>
2008-01-11 05:04:28 +01:00
# include <wx/filefn.h>
# include <wx/utils.h>
2006-01-16 22:02:54 +01:00
# include "options.h"
# include "text_file_reader.h"
# include "text_file_writer.h"
2006-02-21 22:23:52 +01:00
# include "colorspace.h"
# include "utils.h"
2006-01-16 22:02:54 +01:00
///////////////
// Constructor
OptionsManager : : OptionsManager ( ) {
modified = false ;
2008-01-21 00:57:03 +01:00
overriding = false ;
2008-01-20 05:55:44 +01:00
lastVersion = - 1 ;
2006-01-16 22:02:54 +01:00
}
//////////////
// Destructor
OptionsManager : : ~ OptionsManager ( ) {
2007-01-15 06:38:32 +01:00
Clear ( ) ;
}
/////////
// Clear
void OptionsManager : : Clear ( ) {
2006-01-16 22:02:54 +01:00
opt . clear ( ) ;
2007-01-15 06:38:32 +01:00
optType . clear ( ) ;
2006-01-16 22:02:54 +01:00
}
///////////////////////
// Load default values
2008-01-21 00:57:03 +01:00
void OptionsManager : : LoadDefaults ( bool onlyDefaults , bool doOverride ) {
2006-12-18 03:44:38 +01:00
///// PUBLIC //////
// Here go the options that can be edited by the options menu
2008-01-20 05:55:44 +01:00
2008-01-21 00:57:03 +01:00
if ( doOverride ) overriding = true ;
2008-01-20 05:55:44 +01:00
if ( onlyDefaults ) lastVersion = - 1 ;
2006-12-18 03:44:38 +01:00
// General
2007-01-03 04:47:08 +01:00
SetModificationType ( MOD_AUTOMATIC ) ;
2006-12-18 03:44:38 +01:00
SetBool ( _T ( " Tips enabled " ) , true ) ;
SetBool ( _T ( " Show splash " ) , true ) ;
2007-06-21 08:14:49 +02:00
SetBool ( _T ( " Local config " ) , false ) ;
2007-01-14 23:57:25 +01:00
SetInt ( _T ( " Undo levels " ) , 8 ) ;
2006-07-01 07:34:39 +02:00
SetInt ( _T ( " Recent timecodes max " ) , 16 ) ;
2006-12-18 18:18:14 +01:00
SetInt ( _T ( " Recent keyframes max " ) , 16 ) ;
2006-01-16 22:02:54 +01:00
SetInt ( _T ( " Recent sub max " ) , 16 ) ;
SetInt ( _T ( " Recent vid max " ) , 16 ) ;
SetInt ( _T ( " Recent aud max " ) , 16 ) ;
SetInt ( _T ( " Recent find max " ) , 16 ) ;
SetInt ( _T ( " Recent replace max " ) , 16 ) ;
2007-01-14 23:57:25 +01:00
SetInt ( _T ( " Auto check for updates " ) , - 1 ) ;
2006-01-16 22:02:54 +01:00
2006-12-18 03:44:38 +01:00
// File Save/Load
2007-01-03 06:33:17 +01:00
SetModificationType ( MOD_RESTART ) ;
2007-05-16 00:40:20 +02:00
SetInt ( _T ( " Auto save every seconds " ) , 60 ) ; // FIXME: this shouldn't need to require a restart
2007-01-03 04:47:08 +01:00
SetModificationType ( MOD_AUTOMATIC ) ;
2007-06-05 20:02:54 +02:00
SetText ( _T ( " Auto save path " ) , _T ( " autosave " ) ) ; // what does this mean on linux? actually this should be under $HOME on any OS
2007-01-03 06:33:17 +01:00
SetBool ( _T ( " Auto backup " ) , true ) ;
SetText ( _T ( " Auto backup path " ) , _T ( " autoback " ) ) ;
2006-12-18 03:44:38 +01:00
SetText ( _T ( " Auto recovery path " ) , _T ( " recovered " ) ) ;
SetInt ( _T ( " Autoload linked files " ) , 2 ) ;
2007-01-02 23:10:45 +01:00
SetText ( _T ( " Text actor separator " ) , _T ( " : " ) ) ;
SetText ( _T ( " Text comment starter " ) , _T ( " # " ) ) ;
2007-01-14 23:57:25 +01:00
SetText ( _T ( " Save charset " ) , _T ( " UTF-8 " ) ) ;
SetBool ( _T ( " Use nonstandard milisecond times " ) , false ) ;
2007-01-03 06:33:17 +01:00
SetBool ( _T ( " Auto save on every change " ) , false ) ;
2006-12-18 03:44:38 +01:00
2007-01-03 04:47:08 +01:00
// Edit Box
2008-01-20 05:55:44 +01:00
SetModificationType ( MOD_RESTART ) ;
SetText ( _T ( " Dictionaries path " ) , _T ( " dictionaries " ) ) ;
2007-04-22 04:03:40 +02:00
SetText ( _T ( " Spell Checker " ) , _T ( " hunspell " ) ) ;
2008-01-20 05:55:44 +01:00
SetModificationType ( MOD_AUTOMATIC ) ;
2007-01-14 23:57:25 +01:00
SetBool ( _T ( " Link time boxes commit " ) , true ) ;
2007-06-23 08:07:32 +02:00
# ifdef WIN32
SetBool ( _T ( " Insert mode on time boxes " ) , true ) ;
# else
SetBool ( _T ( " Insert mode on time boxes " ) , false ) ;
# endif
2007-01-03 22:49:13 +01:00
SetModificationType ( MOD_EDIT_BOX ) ;
2008-01-20 05:55:44 +01:00
SetBool ( _T ( " Call tips enabled " ) , false , 1700 ) ;
2007-01-14 23:57:25 +01:00
SetBool ( _T ( " Syntax highlight enabled " ) , true ) ;
2007-01-03 06:33:17 +01:00
// Edit box cosmetic
2007-01-03 04:47:08 +01:00
SetColour ( _T ( " Syntax Highlight Normal " ) , wxColour ( 0 , 0 , 0 ) ) ;
SetColour ( _T ( " Syntax Highlight Brackets " ) , wxColour ( 20 , 50 , 255 ) ) ;
SetColour ( _T ( " Syntax Highlight Slashes " ) , wxColour ( 255 , 0 , 200 ) ) ;
SetColour ( _T ( " Syntax Highlight Tags " ) , wxColour ( 90 , 90 , 90 ) ) ;
SetColour ( _T ( " Syntax Highlight Parameters " ) , wxColour ( 40 , 90 , 40 ) ) ;
SetColour ( _T ( " Syntax Highlight Error " ) , wxColour ( 200 , 0 , 0 ) ) ;
SetColour ( _T ( " Syntax Highlight Error Background " ) , wxColour ( 255 , 200 , 200 ) ) ;
SetColour ( _T ( " Syntax Highlight Line Break " ) , wxColour ( 160 , 160 , 160 ) ) ;
2007-08-06 16:29:43 +02:00
SetColour ( _T ( " Syntax Highlight Karaoke Template " ) , wxColour ( 128 , 0 , 192 ) ) ;
2007-01-03 04:47:08 +01:00
SetColour ( _T ( " Edit Box Need Enter Background " ) , wxColour ( 192 , 192 , 255 ) ) ;
# if defined(__WINDOWS__)
2007-01-03 23:43:05 +01:00
SetInt ( _T ( " Edit Font Size " ) , 9 ) ;
2007-01-03 04:47:08 +01:00
# else
2007-01-03 23:43:05 +01:00
SetInt ( _T ( " Edit Font Size " ) , 11 ) ;
2007-01-03 04:47:08 +01:00
# endif
2007-01-03 23:43:05 +01:00
SetText ( _T ( " Edit Font Face " ) , _T ( " " ) ) ;
2007-01-01 05:15:54 +01:00
2006-12-18 03:44:38 +01:00
// Video Options
2007-01-03 22:49:13 +01:00
SetModificationType ( MOD_AUTOMATIC ) ;
2006-12-18 03:44:38 +01:00
SetInt ( _T ( " Video Check Script Res " ) , 0 ) ;
SetInt ( _T ( " Video Default Zoom " ) , 7 ) ;
SetInt ( _T ( " Video Fast Jump Step " ) , 10 ) ;
2008-01-20 05:55:44 +01:00
SetText ( _T ( " Video Screenshot Path " ) , _T ( " ?video " ) , 1700 ) ;
2007-01-04 02:13:46 +01:00
SetModificationType ( MOD_VIDEO ) ;
2006-01-16 22:02:54 +01:00
SetBool ( _T ( " Show keyframes on video slider " ) , true ) ;
2007-06-28 23:35:37 +02:00
SetBool ( _T ( " Show overscan mask " ) , false ) ;
2006-01-16 22:02:54 +01:00
2006-12-18 03:44:38 +01:00
// Video Provider (Advanced)
2007-04-08 21:27:46 +02:00
SetModificationType ( MOD_VIDEO_RELOAD ) ;
2008-01-20 05:55:44 +01:00
SetInt ( _T ( " Avisynth MemoryMax " ) , 64 , 1700 ) ;
SetBool ( _T ( " Threaded Video " ) , false , 1700 ) ;
2008-03-07 03:32:29 +01:00
# ifdef __WINDOWS__
2008-01-20 05:55:44 +01:00
SetText ( _T ( " Video Provider " ) , _T ( " Avisynth " ) , 1700 ) ;
2008-03-07 03:32:29 +01:00
# else
SetText ( _T ( " Video Provider " ) , _T ( " FFMPEG " ) , 1945 ) ;
# endif
2008-01-20 05:55:44 +01:00
SetBool ( _T ( " Allow Ancient Avisynth " ) , false , 1700 ) ;
SetText ( _T ( " Avisynth subs renderer " ) , _T ( " vsfilter " ) , 1700 ) ;
SetBool ( _T ( " Avisynth render own subs " ) , true , 1700 ) ;
2007-04-08 21:27:46 +02:00
# ifdef __WINDOWS__
2008-01-20 05:55:44 +01:00
SetText ( _T ( " Subtitles Provider " ) , _T ( " csri/vsfilter_textsub " ) , 1700 ) ;
2007-04-08 21:27:46 +02:00
# else
SetText ( _T ( " Subtitles Provider " ) , _T ( " csri/asa " ) ) ;
# endif
2008-01-20 05:55:44 +01:00
SetBool ( _T ( " Video Use Pixel Shaders " ) , false , 1700 ) ;
2006-12-18 03:44:38 +01:00
// Audio Options
2007-04-08 21:27:46 +02:00
SetModificationType ( MOD_AUTOMATIC ) ;
2007-04-09 20:25:58 +02:00
SetBool ( _T ( " Audio grab times on select " ) , true ) ;
2006-12-18 03:44:38 +01:00
SetBool ( _T ( " Audio Autofocus " ) , false ) ;
SetBool ( _T ( " Audio Wheel Default To Zoom " ) , false ) ;
SetBool ( _T ( " Audio lock scroll on cursor " ) , false ) ;
2007-04-07 04:39:18 +02:00
SetBool ( _T ( " Audio snap to keyframes " ) , false ) ;
SetBool ( _T ( " Audio snap to other lines " ) , false ) ;
2006-12-18 03:44:38 +01:00
SetInt ( _T ( " Timing Default Duration " ) , 2000 ) ;
SetInt ( _T ( " Audio lead in " ) , 200 ) ;
SetInt ( _T ( " Audio lead out " ) , 300 ) ;
2007-01-04 02:13:46 +01:00
SetModificationType ( MOD_AUDIO ) ;
2006-12-18 03:44:38 +01:00
SetInt ( _T ( " Audio Inactive Lines Display Mode " ) , 1 ) ;
2008-01-10 21:49:31 +01:00
SetBool ( _T ( " Disable Dragging Times " ) , false ) ;
2006-12-18 03:44:38 +01:00
2007-01-04 04:12:41 +01:00
// Audio Advanced
2007-04-10 04:55:23 +02:00
SetModificationType ( MOD_AUDIO_RELOAD ) ;
2008-01-20 05:55:44 +01:00
SetInt ( _T ( " Audio Cache " ) , 1 , 1700 ) ;
2007-06-05 20:02:54 +02:00
# if defined(__WINDOWS__)
2008-03-07 03:32:29 +01:00
SetText ( _T ( " Audio Player " ) , _T ( " DirectSound " ) , 1945 ) ;
SetText ( _T ( " Audio Provider " ) , _T ( " avisynth " ) , 1700 ) ;
2007-06-05 20:02:54 +02:00
# elif defined(__APPLE__)
2007-09-12 01:22:26 +02:00
SetText ( _T ( " Audio Player " ) , _T ( " openal " ) ) ;
2008-03-07 03:32:29 +01:00
SetText ( _T ( " Audio Provider " ) , _T ( " FFMPEG " ) , 1945 ) ;
2007-04-23 00:38:49 +02:00
# else
2007-06-05 20:02:54 +02:00
SetText ( _T ( " Audio Player " ) , _T ( " portaudio " ) ) ; // FIXME: should this be something else? perhaps alsa on linux and portaudio on everything else?
2008-03-07 03:32:29 +01:00
SetText ( _T ( " Audio Provider " ) , _T ( " FFMPEG " ) , 1945 ) ;
2007-04-23 00:38:49 +02:00
# endif
2008-01-20 05:55:44 +01:00
SetText ( _T ( " Audio Downmixer " ) , _T ( " ConvertToMono " ) , 1700 ) ;
2007-04-23 19:01:00 +02:00
SetText ( _T ( " Audio Alsa Device " ) , _T ( " plughw:0,0 " ) ) ;
2008-01-20 05:55:44 +01:00
SetText ( _T ( " Audio HD Cache Location " ) , _T ( " default " ) , 1700 ) ;
SetText ( _T ( " Audio HD Cache Name " ) , _T ( " audio%02i.tmp " ) , 1700 ) ;
2007-06-24 22:46:52 +02:00
// Technically these can do with just the spectrum object being re-created
2007-01-07 08:28:39 +01:00
SetInt ( _T ( " Audio Spectrum Cutoff " ) , 0 ) ;
2007-10-19 05:32:53 +02:00
SetInt ( _T ( " Audio Spectrum Quality " ) , 1 ) ;
SetInt ( _T ( " Audio Spectrum Memory Max " ) , 128 ) ; // megabytes
2006-12-18 03:44:38 +01:00
// Automation
2007-06-05 20:02:54 +02:00
// The path changes only take effect when a script is (re)loaded but Automatic should be good enough, it certainly doesn't warrart a restart
SetModificationType ( MOD_AUTOMATIC ) ;
2008-01-20 05:55:44 +01:00
SetText ( _T ( " Automation Base Path " ) , _T ( " ?data/automation/ " ) , 1700 ) ;
SetText ( _T ( " Automation Include Path " ) , _T ( " ?user/automation/include/|?data/automation/include/ " ) , 1700 ) ;
SetText ( _T ( " Automation Autoload Path " ) , _T ( " ?user/automation/autoload/|?data/automation/autoload/ " ) , 1700 ) ;
2006-12-28 23:31:33 +01:00
SetInt ( _T ( " Automation Trace Level " ) , 3 ) ;
2007-01-10 03:51:11 +01:00
SetInt ( _T ( " Automation Thread Priority " ) , 1 ) ; // "below normal"
2007-07-03 20:26:35 +02:00
SetInt ( _T ( " Automation Autoreload Mode " ) , 1 ) ; // local only
2007-01-04 02:13:46 +01:00
2006-02-21 22:23:52 +01:00
// Generate colors
2007-05-16 00:40:20 +02:00
// FIXME: Can't reliably store the system colour-based ones in the config file, the user might change colour scheme
2006-02-21 22:23:52 +01:00
wxColour tempCol = wxSystemSettings : : GetColour ( wxSYS_COLOUR_WINDOW ) ;
wxColour textCol = wxSystemSettings : : GetColour ( wxSYS_COLOUR_WINDOWTEXT ) ;
wxColour background = wxSystemSettings : : GetColour ( wxSYS_COLOUR_WINDOW ) ;
wxColour comment = wxColour ( 216 , 222 , 245 ) ;
wxColour selection = wxColour ( 206 , 255 , 231 ) ;
wxColour selComment = wxColour ( 211 , 238 , 238 ) ;
wxColour header = wxColour ( 165 , 207 , 231 ) ;
wxColour labels = wxColour ( 196 , 236 , 201 ) ;
wxColour inframe = wxColour ( 255 , 253 , 234 ) ;
wxColour active = wxColour ( 255 , 91 , 239 ) ;
wxColour grid = wxColour ( 128 , 128 , 128 ) ;
wxColour collision = wxColour ( 255 , 0 , 0 ) ;
2007-01-04 00:29:03 +01:00
// Grid
SetModificationType ( MOD_GRID ) ;
SetBool ( _T ( " Grid allow focus " ) , true ) ;
SetBool ( _T ( " Highlight subs in frame " ) , true ) ;
2006-12-18 03:44:38 +01:00
// Grid cosmetic
2006-02-21 22:23:52 +01:00
SetColour ( _T ( " Grid standard foreground " ) , textCol ) ;
SetColour ( _T ( " Grid selection background " ) , selection ) ;
SetColour ( _T ( " Grid selection foreground " ) , textCol ) ;
SetColour ( _T ( " Grid comment background " ) , comment ) ;
SetColour ( _T ( " Grid collision foreground " ) , collision ) ;
SetColour ( _T ( " Grid selected comment background " ) , selComment ) ;
SetColour ( _T ( " Grid inframe background " ) , inframe ) ;
SetColour ( _T ( " Grid background " ) , background ) ;
SetColour ( _T ( " Grid header " ) , header ) ;
SetColour ( _T ( " Grid left column " ) , labels ) ;
SetColour ( _T ( " Grid active border " ) , active ) ;
SetColour ( _T ( " Grid lines " ) , grid ) ;
2007-01-02 23:10:45 +01:00
# if defined(__WINDOWS__)
SetInt ( _T ( " Grid font size " ) , 8 ) ;
# else
SetInt ( _T ( " Grid font size " ) , 10 ) ;
# endif
2007-01-03 23:43:05 +01:00
SetText ( _T ( " Grid Font Face " ) , _T ( " " ) ) ;
2007-01-04 00:29:03 +01:00
wchar_t temp = 0x2600 ;
SetText ( _T ( " Grid hide overrides char " ) , temp ) ;
SetModificationType ( MOD_AUTOMATIC ) ;
2006-12-18 03:44:38 +01:00
// Audio Cosmetic
2007-01-04 02:13:46 +01:00
SetModificationType ( MOD_AUDIO ) ;
2007-01-04 04:12:41 +01:00
SetInt ( _T ( " Audio Line boundaries Thickness " ) , 2 ) ;
SetBool ( _T ( " Audio Draw Secondary Lines " ) , true ) ;
SetBool ( _T ( " Audio Draw Selection Background " ) , true ) ;
2007-04-07 04:39:18 +02:00
SetBool ( _T ( " Audio Draw Keyframes " ) , true ) ;
2007-01-06 07:14:35 +01:00
SetBool ( _T ( " Audio Draw Timeline " ) , true ) ;
SetBool ( _T ( " Audio Draw Cursor Time " ) , true ) ;
2008-01-20 05:56:44 +01:00
SetBool ( _T ( " Audio Draw Video Position " ) , false , 1700 ) ;
2006-12-18 03:44:38 +01:00
SetColour ( _T ( " Audio Selection Background Modified " ) , wxColour ( 92 , 0 , 0 ) ) ;
SetColour ( _T ( " Audio Selection Background " ) , wxColour ( 64 , 64 , 64 ) ) ;
SetColour ( _T ( " Audio Seconds Boundaries " ) , wxColour ( 0 , 100 , 255 ) ) ;
2007-04-13 03:29:05 +02:00
SetColour ( _T ( " Audio Waveform Modified " ) , wxColour ( 255 , 230 , 230 ) ) ;
2006-12-18 03:44:38 +01:00
SetColour ( _T ( " Audio Waveform Selected " ) , wxColour ( 255 , 255 , 255 ) ) ;
SetColour ( _T ( " Audio Waveform Inactive " ) , wxColour ( 0 , 80 , 0 ) ) ;
SetColour ( _T ( " Audio Waveform " ) , wxColour ( 0 , 200 , 0 ) ) ;
2008-01-20 05:55:44 +01:00
SetColour ( _T ( " Audio Line boundary start " ) , wxColour ( 216 , 0 , 0 ) , 1700 ) ;
SetColour ( _T ( " Audio Line boundary end " ) , wxColour ( 230 , 125 , 0 ) , 1700 ) ;
2006-12-18 03:44:38 +01:00
SetColour ( _T ( " Audio Line boundary inactive line " ) , wxColour ( 128 , 128 , 128 ) ) ;
SetColour ( _T ( " Audio Syllable boundaries " ) , wxColour ( 255 , 255 , 0 ) ) ;
SetColour ( _T ( " Audio Syllable text " ) , wxColour ( 255 , 0 , 0 ) ) ;
SetColour ( _T ( " Audio Play cursor " ) , wxColour ( 255 , 255 , 255 ) ) ;
SetColour ( _T ( " Audio Background " ) , wxColour ( 0 , 0 , 0 ) ) ;
2007-01-03 04:47:08 +01:00
SetModificationType ( MOD_OFF ) ;
2006-12-18 03:44:38 +01:00
2007-04-18 06:03:22 +02:00
// Only defaults?
2008-01-21 00:57:03 +01:00
if ( ! onlyDefaults ) {
///// INTERNAL //////
// Options that are set by the program itself
SetInt ( _T ( " Video Dummy Last Width " ) , 640 ) ;
SetInt ( _T ( " Video Dummy Last Height " ) , 480 ) ;
SetColour ( _T ( " Video Dummy Last Colour " ) , wxColour ( 47 , 163 , 254 ) ) ;
SetFloat ( _T ( " Video Dummy Last FPS " ) , 23.976 ) ;
SetInt ( _T ( " Video Dummy Last Length " ) , 40000 ) ;
SetBool ( _T ( " Video Dummy Pattern " ) , false ) ;
SetInt ( _T ( " Locale Code " ) , - 1 , 1700 ) ;
SetBool ( _T ( " Sync video with subs " ) , true ) ;
SetText ( _T ( " Spell checker language " ) , _T ( " en_US " ) ) ;
SetText ( _T ( " Thesaurus language " ) , _T ( " en_US " ) ) ;
SetInt ( _T ( " Options Page " ) , 0 ) ;
SetBool ( _T ( " Audio Link " ) , true ) ;
SetBool ( _T ( " Audio Autocommit " ) , false ) ;
SetBool ( _T ( " Audio Autoscroll " ) , true ) ;
SetBool ( _T ( " Audio Medusa Timing Hotkeys " ) , false ) ;
SetBool ( _T ( " Audio Next Line on Commit " ) , true ) ;
SetBool ( _T ( " Shift Times ByTime " ) , true ) ;
SetInt ( _T ( " Shift Times Type " ) , 0 ) ;
SetInt ( _T ( " Shift Times Length " ) , 0 ) ;
SetInt ( _T ( " Shift Times Affect " ) , 0 ) ;
SetBool ( _T ( " Shift Times Direction " ) , true ) ;
SetInt ( _T ( " Tips current " ) , 0 ) ;
SetBool ( _T ( " Show associations " ) , true , 1700 ) ;
SetBool ( _T ( " Maximized " ) , false ) ;
SetBool ( _T ( " Find Match Case " ) , false ) ;
SetBool ( _T ( " Find RegExp " ) , false ) ;
SetBool ( _T ( " Find Update Video " ) , false ) ;
SetInt ( _T ( " Find Affect " ) , 0 ) ;
SetInt ( _T ( " Find Field " ) , 0 ) ;
SetInt ( _T ( " Grid hide overrides " ) , 1 ) ;
for ( int i = 0 ; i < 10 ; i + + ) SetBool ( _T ( " Grid show column " ) + IntegerToString ( i ) , true ) ;
for ( int i = 0 ; i < 9 ; i + + ) SetBool ( wxString : : Format ( _T ( " Paste Over #%i " ) , i ) , false ) ;
SetBool ( _T ( " Paste Over #9 " ) , true ) ;
SetText ( _T ( " Fonts Collector Destination " ) , _T ( " ?script " ) ) ;
SetInt ( _T ( " Fonts Collector Action " ) , 0 ) ;
2008-01-27 19:30:16 +01:00
SetInt ( _T ( " Audio Display Height " ) , 200 , 1784 ) ;
2008-01-21 00:57:03 +01:00
SetBool ( _T ( " Audio Spectrum " ) , false ) ;
SetInt ( _T ( " Audio Sample Rate " ) , 0 ) ;
SetBool ( _T ( " Video Visual Realtime " ) , true ) ;
SetBool ( _T ( " Detached video " ) , false ) ;
SetInt ( _T ( " Detached video last x " ) , - 1 ) ;
SetInt ( _T ( " Detached video last y " ) , - 1 ) ;
SetBool ( _T ( " Detached video maximized " ) , false ) ;
SetInt ( _T ( " Timing processor key start before thres " ) , 5 ) ;
SetInt ( _T ( " Timing processor key start after thres " ) , 4 ) ;
SetInt ( _T ( " Timing processor key end before thres " ) , 5 ) ;
SetInt ( _T ( " Timing processor key end after thres " ) , 6 ) ;
2008-01-27 23:09:47 +01:00
SetInt ( _T ( " Timing processor adjacent thres " ) , 300 ) ;
2008-01-21 00:57:03 +01:00
SetBool ( _T ( " Timing processor Enable lead-in " ) , true ) ;
SetBool ( _T ( " Timing processor Enable lead-out " ) , true ) ;
SetBool ( _T ( " Timing processor Enable keyframe " ) , true ) ;
2008-01-27 23:09:47 +01:00
SetBool ( _T ( " Timing processor Enable adjacent " ) , true ) ;
2008-01-21 00:57:03 +01:00
SetBool ( _T ( " Timing processor Only Selection " ) , false ) ;
2008-01-27 23:09:47 +01:00
SetFloat ( _T ( " Timing processor adjacent bias " ) , 1.0 ) ;
2008-01-21 00:57:03 +01:00
SetText ( _T ( " Select Text " ) , _T ( " " ) ) ;
SetInt ( _T ( " Select Condition " ) , 0 ) ;
SetInt ( _T ( " Select Field " ) , 0 ) ;
SetInt ( _T ( " Select Action " ) , 0 ) ;
SetInt ( _T ( " Select Mode " ) , 1 ) ;
SetBool ( _T ( " Select Match case " ) , false ) ;
SetBool ( _T ( " Select Match dialogues " ) , true ) ;
SetBool ( _T ( " Select Match comments " ) , false ) ;
SetText ( _T ( " Color Picker Recent " ) , _T ( " &H000000& &H0000FF& &H00FFFF& &H00FF00& &HFFFF00& &HFF0000& &HFF00FF& &HFFFFFF& " ) ) ;
SetInt ( _T ( " Color Picker Mode " ) , 4 , 1700 ) ;
SetText ( _T ( " Last open subtitles path " ) , _T ( " " ) ) ;
SetText ( _T ( " Last open video path " ) , _T ( " " ) ) ;
SetText ( _T ( " Last open audio path " ) , _T ( " " ) ) ;
SetText ( _T ( " Last open timecodes path " ) , _T ( " " ) ) ;
SetText ( _T ( " Last open keyframes path " ) , _T ( " " ) ) ;
SetText ( _T ( " Last open automation path " ) , _T ( " " ) ) ;
SetBool ( _T ( " kanji timer interpolation " ) , true ) ;
wxString previewText = _T ( " Aegisub \\ N0123 " ) ;
previewText + = 0x6708 ; // kanji "moon"
previewText + = 0x8a9e ; // kanji "speak"
SetText ( _T ( " Style editor preview text " ) , previewText ) ;
SetColour ( _T ( " Style editor preview background " ) , wxColour ( 125 , 153 , 176 ) ) ;
2008-01-20 05:55:44 +01:00
}
2007-04-18 06:03:22 +02:00
2008-01-20 05:55:44 +01:00
lastVersion = - 1 ;
2008-01-21 00:57:03 +01:00
overriding = false ;
2006-01-16 22:02:54 +01:00
}
////////////////
// Set filename
void OptionsManager : : SetFile ( wxString file ) {
filename = file ;
}
////////
// Save
void OptionsManager : : Save ( ) {
// Check if it's actually modified
if ( ! modified ) return ;
// Open file
TextFileWriter file ( filename , _T ( " UTF-8 " ) ) ;
file . WriteLineToFile ( _T ( " [Config] " ) ) ;
// Put variables in it
for ( std : : map < wxString , VariableData > : : iterator cur = opt . begin ( ) ; cur ! = opt . end ( ) ; cur + + ) {
file . WriteLineToFile ( ( * cur ) . first + _T ( " = " ) + ( * cur ) . second . AsText ( ) ) ;
}
// Close
modified = false ;
}
////////
// Load
void OptionsManager : : Load ( ) {
2007-06-21 08:14:49 +02:00
// Check if file exists
2006-01-16 22:02:54 +01:00
wxFileName path ( filename ) ;
if ( ! path . FileExists ( ) ) {
modified = true ;
return ;
}
// Read header
TextFileReader file ( filename ) ;
wxString header = file . ReadLineFromFile ( ) ;
2008-01-11 05:04:28 +01:00
if ( header ! = _T ( " [Config] " ) ) {
wxMessageBox ( _ ( " Configuration file is either invalid or corrupt. The current file will be backed up and replaced with a default file. " ) , _ ( " Error " ) , wxCENTRE | wxICON_WARNING ) ;
wxRenameFile ( filename , filename + wxString : : Format ( _T ( " .%i.backup " ) , wxGetUTCTime ( ) ) ) ;
modified = true ;
return ;
}
2006-01-16 22:02:54 +01:00
// Get variables
std : : map < wxString , VariableData > : : iterator cur ;
wxString curLine ;
while ( file . HasMoreLines ( ) ) {
// Parse line
curLine = file . ReadLineFromFile ( ) ;
2006-02-20 22:32:58 +01:00
if ( curLine . IsEmpty ( ) ) continue ;
2006-01-16 22:02:54 +01:00
size_t pos = curLine . Find ( _T ( " = " ) ) ;
if ( pos = = wxString : : npos ) continue ;
wxString key = curLine . Left ( pos ) ;
wxString value = curLine . Mid ( pos + 1 ) ;
// Find it
cur = opt . find ( key ) ;
if ( cur ! = opt . end ( ) ) {
( * cur ) . second . ResetWith ( value ) ;
}
else SetText ( key , value ) ;
}
2008-01-20 05:55:44 +01:00
// Get last version
if ( IsDefined ( _T ( " Last Version " ) ) ) {
long temp ;
AsText ( _T ( " Last Version " ) ) . ToLong ( & temp ) ;
lastVersion = temp ;
}
else lastVersion = 1 ; // This was implemented in 1784, assume that anything before that is 1.
2006-01-16 22:02:54 +01:00
}
/////////////
// Write int
2008-01-20 05:55:44 +01:00
void OptionsManager : : SetInt ( wxString key , int param , int ifLastVersion ) {
2008-01-21 00:57:03 +01:00
if ( ifLastVersion = = - 1 ) {
if ( overriding ) ifLastVersion = 0 ;
else ifLastVersion = 0x7FFFFFFF ;
}
2008-01-20 05:55:44 +01:00
if ( lastVersion > = ifLastVersion ) return ;
2006-01-16 22:02:54 +01:00
opt [ key . Lower ( ) ] . SetInt ( param ) ;
2007-01-03 04:47:08 +01:00
if ( curModType ! = MOD_OFF ) optType [ key . Lower ( ) ] = curModType ;
2006-01-16 22:02:54 +01:00
modified = true ;
}
///////////////
// Write float
2008-01-20 05:55:44 +01:00
void OptionsManager : : SetFloat ( wxString key , double param , int ifLastVersion ) {
2008-01-21 00:57:03 +01:00
if ( ifLastVersion = = - 1 ) {
if ( overriding ) ifLastVersion = 0 ;
else ifLastVersion = 0x7FFFFFFF ;
}
2008-01-20 05:55:44 +01:00
if ( lastVersion > = ifLastVersion ) return ;
2006-01-16 22:02:54 +01:00
opt [ key . Lower ( ) ] . SetFloat ( param ) ;
2007-01-03 04:47:08 +01:00
if ( curModType ! = MOD_OFF ) optType [ key . Lower ( ) ] = curModType ;
2006-01-16 22:02:54 +01:00
modified = true ;
}
////////////////
// Write string
2008-01-20 05:55:44 +01:00
void OptionsManager : : SetText ( wxString key , wxString param , int ifLastVersion ) {
2008-01-21 00:57:03 +01:00
if ( ifLastVersion = = - 1 ) {
if ( overriding ) ifLastVersion = 0 ;
else ifLastVersion = 0x7FFFFFFF ;
}
2008-01-20 05:55:44 +01:00
if ( lastVersion > = ifLastVersion ) return ;
2006-01-16 22:02:54 +01:00
opt [ key . Lower ( ) ] . SetText ( param ) ;
2007-01-03 04:47:08 +01:00
if ( curModType ! = MOD_OFF ) optType [ key . Lower ( ) ] = curModType ;
2006-01-16 22:02:54 +01:00
modified = true ;
}
/////////////////
// Write boolean
2008-01-20 05:55:44 +01:00
void OptionsManager : : SetBool ( wxString key , bool param , int ifLastVersion ) {
2008-01-21 00:57:03 +01:00
if ( ifLastVersion = = - 1 ) {
if ( overriding ) ifLastVersion = 0 ;
else ifLastVersion = 0x7FFFFFFF ;
}
2008-01-20 05:55:44 +01:00
if ( lastVersion > = ifLastVersion ) return ;
2006-01-16 22:02:54 +01:00
opt [ key . Lower ( ) ] . SetBool ( param ) ;
2007-01-03 04:47:08 +01:00
if ( curModType ! = MOD_OFF ) optType [ key . Lower ( ) ] = curModType ;
2006-01-16 22:02:54 +01:00
modified = true ;
}
////////////////
// Write colour
2008-01-20 05:55:44 +01:00
void OptionsManager : : SetColour ( wxString key , wxColour param , int ifLastVersion ) {
2008-01-21 00:57:03 +01:00
if ( ifLastVersion = = - 1 ) {
if ( overriding ) ifLastVersion = 0 ;
else ifLastVersion = 0x7FFFFFFF ;
}
2008-01-20 05:55:44 +01:00
if ( lastVersion > = ifLastVersion ) return ;
2006-01-16 22:02:54 +01:00
opt [ key . Lower ( ) ] . SetColour ( param ) ;
2007-01-03 04:47:08 +01:00
if ( curModType ! = MOD_OFF ) optType [ key . Lower ( ) ] = curModType ;
2006-01-16 22:02:54 +01:00
modified = true ;
}
2007-01-03 06:33:17 +01:00
//////////////
// Reset with
void OptionsManager : : ResetWith ( wxString key , wxString param ) {
opt [ key . Lower ( ) ] . ResetWith ( param ) ;
modified = true ;
}
2006-01-16 22:02:54 +01:00
//////////
// As int
int OptionsManager : : AsInt ( wxString key ) {
std : : map < wxString , VariableData > : : iterator cur ;
cur = ( opt . find ( key . Lower ( ) ) ) ;
if ( cur ! = opt . end ( ) ) {
return ( * cur ) . second . AsInt ( ) ;
}
2007-09-12 01:22:26 +02:00
else throw key . c_str ( ) ; //_T("Internal error: Attempted getting undefined configuration setting");
2006-01-16 22:02:54 +01:00
}
//////////////
// As boolean
bool OptionsManager : : AsBool ( wxString key ) {
std : : map < wxString , VariableData > : : iterator cur ;
cur = ( opt . find ( key . Lower ( ) ) ) ;
if ( cur ! = opt . end ( ) ) {
return ( * cur ) . second . AsBool ( ) ;
}
2007-09-12 01:22:26 +02:00
else throw key . c_str ( ) ; //_T("Internal error: Attempted getting undefined configuration setting");
2006-01-16 22:02:54 +01:00
}
////////////
// As float
double OptionsManager : : AsFloat ( wxString key ) {
std : : map < wxString , VariableData > : : iterator cur ;
cur = ( opt . find ( key . Lower ( ) ) ) ;
if ( cur ! = opt . end ( ) ) {
return ( * cur ) . second . AsFloat ( ) ;
}
2007-09-12 01:22:26 +02:00
else throw key . c_str ( ) ; //_T("Internal error: Attempted getting undefined configuration setting");
2006-01-16 22:02:54 +01:00
}
/////////////
// As string
wxString OptionsManager : : AsText ( wxString key ) {
std : : map < wxString , VariableData > : : iterator cur ;
cur = ( opt . find ( key . Lower ( ) ) ) ;
if ( cur ! = opt . end ( ) ) {
return ( * cur ) . second . AsText ( ) ;
}
2007-09-12 01:22:26 +02:00
else throw key . c_str ( ) ; //_T("Internal error: Attempted getting undefined configuration setting");
2006-01-16 22:02:54 +01:00
}
/////////////
// As colour
wxColour OptionsManager : : AsColour ( wxString key ) {
std : : map < wxString , VariableData > : : iterator cur ;
cur = ( opt . find ( key . Lower ( ) ) ) ;
if ( cur ! = opt . end ( ) ) {
return ( * cur ) . second . AsColour ( ) ;
}
2007-09-12 01:22:26 +02:00
else throw key . c_str ( ) ; //_T("Internal error: Attempted getting undefined configuration setting");
2006-01-16 22:02:54 +01:00
}
2007-01-03 04:47:08 +01:00
/////////////////////
// Modification type
ModType OptionsManager : : GetModType ( wxString key ) {
std : : map < wxString , ModType > : : iterator cur ;
cur = ( optType . find ( key . Lower ( ) ) ) ;
if ( cur ! = optType . end ( ) ) {
return ( * cur ) . second ;
}
else return MOD_AUTOMATIC ;
}
2006-01-16 22:02:54 +01:00
///////////////
// Is defined?
bool OptionsManager : : IsDefined ( wxString key ) {
std : : map < wxString , VariableData > : : iterator cur ;
cur = ( opt . find ( key . Lower ( ) ) ) ;
return ( cur ! = opt . end ( ) ) ;
}
/////////////////////////////////////
// Adds an item to a list of recents
void OptionsManager : : AddToRecentList ( wxString entry , wxString list ) {
// Find strings already in recent list
wxArrayString orig ;
wxString cur ;
int recentMax = AsInt ( list + _T ( " max " ) ) ;
int n = 0 ;
for ( int i = 0 ; i < recentMax ; i + + ) {
wxString key = list + _T ( " # " ) + wxString : : Format ( _T ( " %i " ) , i + 1 ) ;
if ( IsDefined ( key ) ) {
cur = AsText ( key ) ;
if ( cur ! = entry ) {
orig . Add ( cur ) ;
n + + ;
}
}
else break ;
}
// Write back to options
SetText ( list + _T ( " #1 " ) , entry ) ;
if ( n > recentMax - 1 ) n = recentMax - 1 ;
for ( int i = 0 ; i < n ; i + + ) {
wxString key = list + _T ( " # " ) + wxString : : Format ( _T ( " %i " ) , i + 2 ) ;
SetText ( key , orig [ i ] ) ;
}
// Save options
Save ( ) ;
}
///////////////////
// Get recent list
wxArrayString OptionsManager : : GetRecentList ( wxString list ) {
wxArrayString work ;
int recentMax = AsInt ( list + _T ( " max " ) ) ;
for ( int i = 0 ; i < recentMax ; i + + ) {
wxString n = wxString : : Format ( _T ( " %i " ) , i + 1 ) ;
wxString key = list + _T ( " # " ) + n ;
if ( IsDefined ( key ) ) {
work . Add ( Options . AsText ( key ) ) ;
}
else break ;
}
return work ;
}
2007-01-03 04:47:08 +01:00
/////////////////////////
// Set modification type
void OptionsManager : : SetModificationType ( ModType type ) {
curModType = type ;
}
2006-01-16 22:02:54 +01:00
///////////////////
// Global instance
OptionsManager Options ;