[synchronicity-commits] SF.net SVN: synchronicity:[185] trunk/Create Synchronicity
Easy, fast, and lightweight backup and synchronization app for Windows
Brought to you by:
createsoftware
From: <cre...@us...> - 2010-02-26 13:04:45
|
Revision: 185 http://synchronicity.svn.sourceforge.net/synchronicity/?rev=185&view=rev Author: createsoftware Date: 2010-02-26 13:04:38 +0000 (Fri, 26 Feb 2010) Log Message: ----------- Cleanly split between constants config strings and program settings: * The ConfigOptions Module is a wrapper around constant values such as setting labels * The ConfigHandler Class holds methods related to dealing with the main configuration file These changes were needed because of initialisation order problems, which crashed the program at startup. NB: The SettingsHandler class is not a singleton, and deals with synchronization profiles. Modified Paths: -------------- trunk/Create Synchronicity/AboutForm.vb trunk/Create Synchronicity/LanguageHandling.vb trunk/Create Synchronicity/LogHandling.vb trunk/Create Synchronicity/MainForm.vb trunk/Create Synchronicity/SettingsForm.vb trunk/Create Synchronicity/SettingsHandling.vb Modified: trunk/Create Synchronicity/AboutForm.vb =================================================================== --- trunk/Create Synchronicity/AboutForm.vb 2010-02-26 11:56:35 UTC (rev 184) +++ trunk/Create Synchronicity/AboutForm.vb 2010-02-26 13:04:38 UTC (rev 185) @@ -8,6 +8,7 @@ Public Class AboutForm Dim Translation As LanguageHandler = LanguageHandler.GetSingleton + Dim ProgramConfig As ConfigHandler = ConfigHandler.GetSingleton Private Sub SetLinkArea(ByVal Link As LinkLabel) If Link.Text.IndexOf("\") = -1 Or Link.Text.IndexOf("/") = -1 Then Exit Sub @@ -33,13 +34,13 @@ SetLinkArea(About_VersionInfo) About_LanguagesList.Items.Clear() - For Each File As String In IO.Directory.GetFiles(ConfigOptions.LanguageRootDir) + For Each File As String In IO.Directory.GetFiles(ProgramConfig.LanguageRootDir) About_LanguagesList.Items.Add(File.Remove(File.LastIndexOf(".")).Substring(File.LastIndexOf("\") + 1)) Next - ConfigOptions.LoadProgramSettings() - About_Updates.Checked = ConfigOptions.GetProgramSetting(ConfigOptions.AutoUpdates, "False") - About_LanguagesList.SelectedIndex = About_LanguagesList.Items.IndexOf(ConfigOptions.GetProgramSetting(ConfigOptions.Language, "")) + ProgramConfig.LoadProgramSettings() + About_Updates.Checked = ProgramConfig.GetProgramSetting(ConfigOptions.AutoUpdates, "False") + About_LanguagesList.SelectedIndex = About_LanguagesList.Items.IndexOf(ProgramConfig.GetProgramSetting(ConfigOptions.Language, "")) End Sub Private Sub About_LinkToProductPage_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles About_LinkToProductPage.LinkClicked @@ -67,12 +68,12 @@ End Sub Private Sub AboutForm_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed - If ConfigOptions.GetProgramSetting(ConfigOptions.Language, ConfigOptions.DefaultLanguage) <> About_LanguagesList.SelectedItem.ToString Then + If ProgramConfig.GetProgramSetting(ConfigOptions.Language, ConfigOptions.DefaultLanguage) <> About_LanguagesList.SelectedItem.ToString Then Interaction.ShowMsg(Translation.Translate("\RESTART"), Translation.Translate("\RESTART_NEEDED")) End If - ConfigOptions.SetProgramSetting(ConfigOptions.AutoUpdates, About_Updates.Checked) - If About_LanguagesList.SelectedIndex <> -1 Then ConfigOptions.SetProgramSetting(ConfigOptions.Language, About_LanguagesList.SelectedItem) - ConfigOptions.SaveProgramSettings() + ProgramConfig.SetProgramSetting(ConfigOptions.AutoUpdates, About_Updates.Checked) + If About_LanguagesList.SelectedIndex <> -1 Then ProgramConfig.SetProgramSetting(ConfigOptions.Language, About_LanguagesList.SelectedItem) + ProgramConfig.SaveProgramSettings() End Sub End Class Modified: trunk/Create Synchronicity/LanguageHandling.vb =================================================================== --- trunk/Create Synchronicity/LanguageHandling.vb 2010-02-26 11:56:35 UTC (rev 184) +++ trunk/Create Synchronicity/LanguageHandling.vb 2010-02-26 13:04:38 UTC (rev 185) @@ -8,15 +8,16 @@ Public Class LanguageHandler Private Shared Instance As LanguageHandler + Dim Configuration As ConfigHandler = ConfigHandler.GetSingleton Protected Sub New() - LoadProgramSettings() - IO.Directory.CreateDirectory(ConfigOptions.LanguageRootDir) + Configuration.LoadProgramSettings() + IO.Directory.CreateDirectory(Configuration.LanguageRootDir) Strings = New Dictionary(Of String, String) - Dim DictFile As String = ConfigOptions.LanguageRootDir & "\" & ConfigOptions.GetProgramSetting(ConfigOptions.Language, ConfigOptions.DefaultLanguage) & ".lng" + Dim DictFile As String = Configuration.LanguageRootDir & "\" & Configuration.GetProgramSetting(ConfigOptions.Language, ConfigOptions.DefaultLanguage) & ".lng" - If Not IO.File.Exists(DictFile) Then DictFile = ConfigOptions.LanguageRootDir & "\" & ConfigOptions.DefaultLanguage & ".lng" + If Not IO.File.Exists(DictFile) Then DictFile = Configuration.LanguageRootDir & "\" & ConfigOptions.DefaultLanguage & ".lng" If Not IO.File.Exists(DictFile) Then Interaction.ShowMsg("No language file found!") Else Modified: trunk/Create Synchronicity/LogHandling.vb =================================================================== --- trunk/Create Synchronicity/LogHandling.vb 2010-02-26 11:56:35 UTC (rev 184) +++ trunk/Create Synchronicity/LogHandling.vb 2010-02-26 13:04:38 UTC (rev 185) @@ -15,11 +15,12 @@ #End If Dim Translation As LanguageHandler = LanguageHandler.GetSingleton + Dim ProgramConfig As ConfigHandler = ConfigHandler.GetSingleton Private Disposed As Boolean Sub New(ByVal _LogName As String) - IO.Directory.CreateDirectory(ConfigOptions.LogRootDir) + IO.Directory.CreateDirectory(ProgramConfig.LogRootDir) Disposed = False LogName = _LogName @@ -102,9 +103,9 @@ Disposed = True Try - Dim NewLog As Boolean = Not IO.File.Exists(ConfigOptions.GetLogPath(LogName)) + Dim NewLog As Boolean = Not IO.File.Exists(ProgramConfig.GetLogPath(LogName)) - Dim LogWriter As New IO.StreamWriter(ConfigOptions.GetLogPath(LogName), True) + Dim LogWriter As New IO.StreamWriter(ProgramConfig.GetLogPath(LogName), True) Try #If Not DEBUG Then Modified: trunk/Create Synchronicity/MainForm.vb =================================================================== --- trunk/Create Synchronicity/MainForm.vb 2010-02-26 11:56:35 UTC (rev 184) +++ trunk/Create Synchronicity/MainForm.vb 2010-02-26 13:04:38 UTC (rev 185) @@ -11,37 +11,38 @@ Dim SettingsArray As Dictionary(Of String, SettingsHandler) Dim Translation As LanguageHandler = LanguageHandler.GetSingleton + Dim ProgramConfig As ConfigHandler = ConfigHandler.GetSingleton #Region " Events " Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load - Me.Icon = ConfigOptions.GetIcon() + Me.Icon = ProgramConfig.GetIcon() - IO.Directory.CreateDirectory(ConfigOptions.LogRootDir) - IO.Directory.CreateDirectory(ConfigOptions.ConfigRootDir) - IO.Directory.CreateDirectory(ConfigOptions.LanguageRootDir) + IO.Directory.CreateDirectory(ProgramConfig.LogRootDir) + IO.Directory.CreateDirectory(ProgramConfig.ConfigRootDir) + IO.Directory.CreateDirectory(ProgramConfig.LanguageRootDir) #If DEBUG Then Interaction.ShowMsg(Translation.Translate("\DEBUG_WARNING"), Translation.Translate("\DEBUG_MODE"), MessageBoxButtons.OK, MessageBoxIcon.Warning) #End If - ConfigOptions.LoadProgramSettings() - If Not ConfigOptions.ProgramSettingsSet(ConfigOptions.AutoUpdates) Or Not ConfigOptions.ProgramSettingsSet(ConfigOptions.Language) Then - If Not ConfigOptions.ProgramSettingsSet(ConfigOptions.AutoUpdates) Then + ProgramConfig.LoadProgramSettings() + If Not ProgramConfig.ProgramSettingsSet(ConfigOptions.AutoUpdates) Or Not ProgramConfig.ProgramSettingsSet(ConfigOptions.Language) Then + If Not ProgramConfig.ProgramSettingsSet(ConfigOptions.AutoUpdates) Then If Interaction.ShowMsg(Translation.Translate("\WELCOME_MSG"), Translation.Translate("\FIRST_RUN"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then - ConfigOptions.SetProgramSetting(ConfigOptions.AutoUpdates, "True") + ProgramConfig.SetProgramSetting(ConfigOptions.AutoUpdates, "True") Else - ConfigOptions.SetProgramSetting(ConfigOptions.AutoUpdates, "False") + ProgramConfig.SetProgramSetting(ConfigOptions.AutoUpdates, "False") End If End If - If Not ConfigOptions.ProgramSettingsSet(ConfigOptions.Language) Then - ConfigOptions.SetProgramSetting(ConfigOptions.Language, ConfigOptions.DefaultLanguage) + If Not ProgramConfig.ProgramSettingsSet(ConfigOptions.Language) Then + ProgramConfig.SetProgramSetting(ConfigOptions.Language, ConfigOptions.DefaultLanguage) End If - ConfigOptions.SaveProgramSettings() + ProgramConfig.SaveProgramSettings() End If - If ConfigOptions.GetProgramSetting(ConfigOptions.AutoUpdates, "False") Then + If ProgramConfig.GetProgramSetting(ConfigOptions.AutoUpdates, "False") Then Dim UpdateThread As New Threading.Thread(AddressOf Updates.CheckForUpdates) UpdateThread.Start(True) End If @@ -102,7 +103,7 @@ Private Sub Main_Actions_AfterLabelEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LabelEditEventArgs) Handles Main_Actions.AfterLabelEdit e.CancelEdit = True Main_Actions.LabelEdit = False - If e.Label = "" OrElse e.Label.IndexOfAny(IO.Path.GetInvalidFileNameChars) >= 0 Then 'OrElse IO.File.Exists(ConfigOptions.GetConfigPath(e.Label)) Then + If e.Label = "" OrElse e.Label.IndexOfAny(IO.Path.GetInvalidFileNameChars) >= 0 Then 'OrElse IO.File.Exists(ProgramConfig.GetConfigPath(e.Label)) Then Exit Sub End If Dim SettingsForm As New Settings(e.Label) @@ -131,7 +132,7 @@ End Sub Private Sub Main_ActionsMenu_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Main_ActionsMenu.Opening - Dim FileSize As Integer = If(IO.File.Exists(ConfigOptions.GetLogPath(CurrentProfile)), CInt((New System.IO.FileInfo(ConfigOptions.GetLogPath(CurrentProfile))).Length / 1000), 0) + Dim FileSize As Integer = If(IO.File.Exists(ProgramConfig.GetLogPath(CurrentProfile)), CInt((New System.IO.FileInfo(ProgramConfig.GetLogPath(CurrentProfile))).Length / 1000), 0) ClearLogMenuItem.Text = String.Format(ClearLogMenuItem.Tag, FileSize) End Sub @@ -164,8 +165,8 @@ End Sub Private Sub ViewLogMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewLogMenuItem.Click - If Not IO.File.Exists(ConfigOptions.GetLogPath(CurrentProfile)) Then Exit Sub - Diagnostics.Process.Start(ConfigOptions.GetLogPath(CurrentProfile)) + If Not IO.File.Exists(ProgramConfig.GetLogPath(CurrentProfile)) Then Exit Sub + Diagnostics.Process.Start(ProgramConfig.GetLogPath(CurrentProfile)) End Sub Private Sub ClearLogMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearLogMenuItem.Click @@ -181,7 +182,7 @@ Main_Actions.Items.Clear() Main_Actions.Items.Add(CreateProfileItem).Group = Main_Actions.Groups(0) - For Each ConfigFile As String In IO.Directory.GetFiles(ConfigOptions.ConfigRootDir, "*.sync") + For Each ConfigFile As String In IO.Directory.GetFiles(ProgramConfig.ConfigRootDir, "*.sync") Dim Name As String = ConfigFile.Substring(ConfigFile.LastIndexOf("\") + 1) Name = Name.Substring(0, Name.LastIndexOf(".")) Modified: trunk/Create Synchronicity/SettingsForm.vb =================================================================== --- trunk/Create Synchronicity/SettingsForm.vb 2010-02-26 11:56:35 UTC (rev 184) +++ trunk/Create Synchronicity/SettingsForm.vb 2010-02-26 13:04:38 UTC (rev 185) @@ -12,6 +12,7 @@ Dim ClickedRightTreeView As Boolean = False Dim Translation As LanguageHandler = LanguageHandler.GetSingleton + Dim ProgramConfig As ConfigHandler = ConfigHandler.GetSingleton 'Note: 'The list called Handler.(left|right)CheckedNodes contains pathes not ending with "*", associated with booleans indicating whether all subfolders /path/ are to be synced. 'The boolean value is stored as a * appended at the end of the file name. @@ -354,7 +355,6 @@ End Function Private Sub Settings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load - Dim Translation As LanguageHandler = LanguageHandler.GetSingleton Translation.TranslateControl(Me) Settings_Update(True) Modified: trunk/Create Synchronicity/SettingsHandling.vb =================================================================== --- trunk/Create Synchronicity/SettingsHandling.vb 2010-02-26 11:56:35 UTC (rev 184) +++ trunk/Create Synchronicity/SettingsHandling.vb 2010-02-26 13:04:38 UTC (rev 185) @@ -27,14 +27,34 @@ Public Const DefaultLanguage As String = "english" Public Const AutoUpdates As String = "Auto updates" - Public ConfigRootDir As String = Application.StartupPath & "\config" - Public LogRootDir As String = Application.StartupPath & "\log" + Public Const ConfigFolderName = "config" + Public Const LogFolderName = "log" + Public Const SettingsFileName = "mainconfig.ini" +End Module + +Public Class ConfigHandler + Private Shared Instance As ConfigHandler + + Public ConfigRootDir As String + Public LogRootDir As String + Public MainConfigFile As String + Public LanguageRootDir As String = Application.StartupPath & "\languages" - Public MainConfigFile As String = ConfigRootDir & "\mainconfig.ini" Dim ProgramSettingsLoaded As Boolean = False Dim ProgramSettings As New Dictionary(Of String, String) + Protected Sub New() + ConfigRootDir = GetUserFilesRootDir() & ConfigFolderName + LogRootDir = GetUserFilesRootDir() & LogFolderName + MainConfigFile = ConfigRootDir & "\" & SettingsFileName + End Sub + + Public Shared Function GetSingleton() As ConfigHandler + If Instance Is Nothing Then Instance = New ConfigHandler() + Return Instance + End Function + Public Function GetConfigPath(ByVal Name As String) As String Return ConfigRootDir & "\" & Name & ".sync" End Function @@ -57,6 +77,30 @@ #End If End Function + Public Function GetUserFilesRootDir() As String 'Return the place were config files are stored + Static UserFilesRootDir As String = String.Empty + If Not UserFilesRootDir = String.Empty Then Return UserFilesRootDir + + Dim AppPathInfo As New IO.DirectoryInfo(Application.StartupPath) + Dim UserPath As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\Create Software\Create Synchronicity\" + + If IO.Directory.Exists(Application.StartupPath & "\" & ConfigFolderName) Then + If Not AppPathInfo.Attributes & IO.FileAttributes.ReadOnly Then + UserFilesRootDir = Application.StartupPath & "\" + Return UserFilesRootDir + Else + Interaction.ShowMsg("Create Synchronicity cannot write in your in your installation directory, although it contains configuration files. Your Application Data folder will therefore be used instead.", "Information", , MessageBoxIcon.Information) + Return UserPath + End If + + ElseIf IO.Directory.Exists(UserPath) Then + Return UserPath + + Else + Return Application.StartupPath & "\" + End If + End Function + Public Function GetProgramSetting(ByVal Key As String, ByVal DefaultVal As String) As String If (ProgramSettings.ContainsKey(Key)) Then Return ProgramSettings(Key) @@ -72,7 +116,7 @@ Public Sub LoadProgramSettings() If ProgramSettingsLoaded Then Exit Sub - IO.Directory.CreateDirectory(ConfigOptions.ConfigRootDir) + IO.Directory.CreateDirectory(ConfigRootDir) If Not IO.File.Exists(MainConfigFile) Then IO.File.Create(MainConfigFile).Close() Exit Sub @@ -103,7 +147,7 @@ Public Function ProgramSettingsSet(ByVal Setting As String) As Boolean Return ProgramSettings.ContainsKey(Setting) End Function -End Module +End Class Class SettingsHandler Public ConfigName As String @@ -114,6 +158,7 @@ Private PredicateConfigMatchingList As Dictionary(Of String, String) Dim Translation As LanguageHandler = LanguageHandler.GetSingleton + Dim ProgramConfig As ConfigHandler = ConfigHandler.GetSingleton Public Sub New(ByVal Name As String) ConfigName = Name @@ -132,8 +177,8 @@ End Sub Function LoadConfigFile() As Boolean - If Not IO.File.Exists(ConfigOptions.GetConfigPath(ConfigName)) Then Exit Function - Dim FileReader As New IO.StreamReader(ConfigOptions.GetConfigPath(ConfigName)) + If Not IO.File.Exists(ProgramConfig.GetConfigPath(ConfigName)) Then Exit Function + Dim FileReader As New IO.StreamReader(ProgramConfig.GetConfigPath(ConfigName)) Configuration.Clear() While Not FileReader.EndOfStream @@ -173,7 +218,7 @@ Function SaveConfigFile() As Boolean Try Dim ConfigString As String = "" - Dim FileWriter As New IO.StreamWriter(ConfigOptions.GetConfigPath(ConfigName)) + Dim FileWriter As New IO.StreamWriter(ProgramConfig.GetConfigPath(ConfigName)) For Each Setting As KeyValuePair(Of String, String) In Configuration FileWriter.WriteLine(Setting.Key & ":" & Setting.Value) @@ -218,12 +263,12 @@ End Function Sub DeleteConfigFile() - IO.File.Delete(ConfigOptions.GetConfigPath(ConfigName)) + IO.File.Delete(ProgramConfig.GetConfigPath(ConfigName)) DeleteLogFile() End Sub Sub DeleteLogFile() - IO.File.Delete(ConfigOptions.GetLogPath(ConfigName)) + IO.File.Delete(ProgramConfig.GetLogPath(ConfigName)) End Sub Sub SetSetting(ByVal SettingName As String, ByVal Value As String) @@ -355,6 +400,7 @@ Public Module Updates Dim Translation As LanguageHandler = LanguageHandler.GetSingleton + Dim ProgramConfig As ConfigHandler = ConfigHandler.GetSingleton Public Sub CheckForUpdates(ByVal RoutineCheck As Boolean) Try This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |