Click here to Skip to main content
15,886,067 members
Articles / Desktop Programming / Windows Forms

SQLite Compare Utility

Rate me:
Please Sign up or sign in to vote.
4.89/5 (68 votes)
21 Feb 2015LGPL35 min read 281.9K   37.1K   131  
Utility for comparing two SQLite database files for both structure and data
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.Windows.Forms;

namespace SQLiteTurbo
{
    /// <summary>
    /// This class provides static properties for system-wide configuration
    /// </summary>
    public class Configuration
    {
        #region Public Static Methods
        /// <summary>
        /// Returns the path to the temporary BLOB file (used when reading or writing BLOB
        /// data to databases).
        /// </summary>
        public static string TempBlobFilePath
        {
            get
            {
                if (_tempBlobFilePath != null)
                    return _tempBlobFilePath;
                string appdata = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                string sqliteAppdata = appdata + "\\SQLiteCompare\\";
                if (!Directory.Exists(sqliteAppdata))
                    Directory.CreateDirectory(sqliteAppdata);
                _tempBlobFilePath = sqliteAppdata + "blob.dat";
                return _tempBlobFilePath;
            }
        }

        /// <summary>
        /// Returns the path tothe log file
        /// </summary>
        public static string LogFilePath
        {
            get
            {
                string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                string sqliteAppdata = appdata + "\\SQLiteCompare\\";
                if (!Directory.Exists(sqliteAppdata))
                    Directory.CreateDirectory(sqliteAppdata);
                return sqliteAppdata + "scompare.log";
            }
        }

        /// <summary>
        /// Used to check if this is the first time the utility is ran
        /// </summary>
        public static bool FirstTime
        {
            get
            {
                object tmp = Registry.GetValue(SQLITE_REG_KEY, FIRST_TIME_VAL, null);
                if (tmp == null)
                    return true;
                else
                    return false;
            }

            set
            {
                Registry.SetValue(SQLITE_REG_KEY, FIRST_TIME_VAL, (value?1:0));
            }
        }

        /// <summary>
        /// Returns the last used left-db path
        /// </summary>
        public static string LastUsedLeftDbPath
        {
            get
            {
                string lpath = (string)Registry.GetValue(SQLITE_REG_KEY, LEFT_DB_REG_VAL, null);
                return lpath;
            }
            set
            {
                Registry.SetValue(SQLITE_REG_KEY, LEFT_DB_REG_VAL, value);
            }
        }

        /// <summary>
        /// Returns the last used right-db path
        /// </summary>
        public static string LastUsedRightDbPath
        {
            get
            {
                string rpath = (string)Registry.GetValue(SQLITE_REG_KEY, RIGHT_DB_REG_VAL, null);
                return rpath;
            }
            set
            {
                Registry.SetValue(SQLITE_REG_KEY, RIGHT_DB_REG_VAL, value);
            }
        }

        /// <summary>
        /// Returns TRUE if the last time a BLOB field comparison was selected.
        /// </summary>
        public static bool LastCompareBlobFields
        {
            get
            {
                object tmp = Registry.GetValue(SQLITE_REG_KEY, BLOB_COMPARE_REG_VAL, 0);
                if (tmp == null || tmp.GetType() != typeof(int))
                    return false;
                int val = (int)tmp;
                if (val == 0)
                    return false;
                else
                    return true;
            }
            set
            {
                Registry.SetValue(SQLITE_REG_KEY, BLOB_COMPARE_REG_VAL, value ? 1 : 0);
            }
        }

        /// <summary>
        /// Returns TRUE if the last time a comparison was performed - it was with data comparison
        /// option turned ON.
        /// </summary>
        public static bool LastComparisonWithData
        {
            get
            {
                object tmp = Registry.GetValue(SQLITE_REG_KEY, DATA_COMPARISON_REG_VAL, 0);
                if (tmp == null || tmp.GetType() != typeof(int))
                    return false;
                int val = (int)tmp;
                if (val == 0)
                    return false;
                else
                    return true;
            }
            set
            {
                Registry.SetValue(SQLITE_REG_KEY, DATA_COMPARISON_REG_VAL, value ? 1 : 0);
            }
        }

        /// <summary>
        /// Get a flag to indicate if we automatically check for software updates on startup.
        /// </summary>
        public static bool CheckUpdatesOnStartup
        {
            get
            {
                object tmp = Registry.GetValue(SQLITE_REG_KEY, CHECK_UPDATES_ON_STARTUP_VAL, 0);
                if (tmp == null || tmp.GetType() != typeof(int))
                    return false;
                int val = (int)tmp;
                if (val == 0)
                    return false;
                return true;
            }
            set
            {
                Registry.SetValue(SQLITE_REG_KEY, CHECK_UPDATES_ON_STARTUP_VAL, value ? 1 : 0);
            }
        }
        #endregion

        #region Constants
        private static string SQLITE_REG_KEY = @"HKEY_CURRENT_USER\SOFTWARE\SQLiteCompare";
        private static string LEFT_DB_REG_VAL = @"LeftDB";
        private static string RIGHT_DB_REG_VAL = @"RightDB";
        private static string FIRST_TIME_VAL = @"FirstTime";
        private static string DATA_COMPARISON_REG_VAL = @"DataComparison";
        private static string BLOB_COMPARE_REG_VAL = @"CompareBlobFields";
        private static string CHECK_UPDATES_ON_STARTUP_VAL = @"CheckUpdatesOnStartup";
        #endregion

        #region Private Variables
        private static string _tempBlobFilePath;
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer
Israel Israel
My name is Liron Levi and I'm developing software for fun & profit for 15 years already.

Comments and Discussions