private static void UpgradeSettingsDatabase() { int version; int initialVersion; // Get DatabaseSetting Version using (SqlCeCommand cmd = new SqlCeCommand("select Version from DatabaseSetting", Program.GetOpenSettingsConnection())) using (SqlCeDataAdapter da = new SqlCeDataAdapter(cmd)) { DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count == 0) { initialVersion = version = 0; } else { initialVersion = version = Convert.ToInt32(ds.Tables[0].Rows[0][0]); } } // Run Upgrades if (version == 0) { using (SqlCeCommand cmd = new SqlCeCommand("create table RecentFile (ID int primary key identity, Path nvarchar(1024) not null)", Program.GetOpenSettingsConnection())) { cmd.ExecuteNonQuery(); } version++; } if (version == 1) { using (SqlCeCommand cmd = new SqlCeCommand("alter table General add CheckForUpdates bit not null default(1)", Program.GetOpenSettingsConnection())) cmd.ExecuteNonQuery(); using (SqlCeCommand cmd = new SqlCeCommand("alter table General add LastUpdateCheck datetime not null default('2002-10-30')", Program.GetOpenSettingsConnection())) cmd.ExecuteNonQuery(); using (SqlCeCommand cmd = new SqlCeCommand("alter table General add UpdateCheckFrequency int not null default(7)", Program.GetOpenSettingsConnection())) cmd.ExecuteNonQuery(); version++; } if (version == 2) { using (SqlCeCommand cmd = new SqlCeCommand("update Creating set ExcludeFilesOfType = ExcludeFilesOfType + ';.sha1';", Program.GetOpenSettingsConnection())) cmd.ExecuteNonQuery(); version++; } if (version == 3) { using (SqlCeCommand cmd = new SqlCeCommand("alter table Checking add AutoVerify bit not null default(1);", Program.GetOpenSettingsConnection())) cmd.ExecuteNonQuery(); version++; } if (version == 4) { using (SqlCeCommand cmd = new SqlCeCommand("alter table Checking add PlaySoundOK bit not null default(1), PlaySoundOK_IfInactive bit not null default(1), PlaySoundError bit not null default(1);", Program.GetOpenSettingsConnection())) cmd.ExecuteNonQuery(); version++; } if (version == 5) { using (SqlCeCommand cmd = new SqlCeCommand("alter table Creating add CreateForEachSubDir bit not null default(0);", Program.GetOpenSettingsConnection())) cmd.ExecuteNonQuery(); version++; } if (version == 6) { using (SqlCeCommand cmd = new SqlCeCommand("create table Comments (ID int primary key identity, WriteComments bit not null, Header nvarchar(2048) not null, Content nvarchar(512) not null, Footer nvarchar(2048) not null);", Program.GetOpenSettingsConnection())) cmd.ExecuteNonQuery(); using (SqlCeCommand cmd = new SqlCeCommand("insert into Comments (WriteComments, Header, Content, Footer) values(1, '', '', '');", Program.GetOpenSettingsConnection())) cmd.ExecuteNonQuery(); CommentSettings comments = new CommentSettings(); comments.Load(); comments.Header = " Using ilSFV on {0:yyyy-MM-dd} at {0:HH:mm.ss}" + Environment.NewLine + " http://cdtag.com/ilsfv"; comments.Content = "{0,13:#,0} {1:HH:mm.ss} {1:yyyy-MM-dd} {2}"; comments.Footer = ""; comments.Save(); version++; } if (version == 7) { using (SqlCeCommand cmd = new SqlCeCommand("alter table General add UseLowPriorityOnHide bit not null default(1)", Program.GetOpenSettingsConnection())) cmd.ExecuteNonQuery(); version++; } if (version == 8) { using (SqlCeCommand cmd = new SqlCeCommand("alter table General add IsRecentFilesSaved bit not null default(1)", Program.GetOpenSettingsConnection())) { cmd.ExecuteNonQuery(); } version++; } // Update DatabaseSetting Version if (initialVersion != version) { if (initialVersion == 0) { using (SqlCeCommand cmd = new SqlCeCommand("insert into DatabaseSetting (Version) values(@Version);", Program.GetOpenSettingsConnection())) { cmd.Parameters.AddWithValue("@Version", version); cmd.ExecuteNonQuery(); } } else { using (SqlCeCommand cmd = new SqlCeCommand("update DatabaseSetting set Version = @Version", Program.GetOpenSettingsConnection())) { cmd.Parameters.AddWithValue("@Version", version); cmd.ExecuteNonQuery(); } } } }