/// <summary>
        /// Database initialization checks
        /// </summary>

        #region Database initialization checks

        public static void DBInitializationChecks()
        {
            try
            {
                string sqliteFile        = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Software\\endpoint.db3";
                string MSIConfigFilePath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Software\\configApp.xml";

                if (!File.Exists(sqliteFile) && File.Exists(MSIConfigFilePath))
                {
                    // Read MSI config file

                    XPathDocument  configMSI    = new XPathDocument(MSIConfigFilePath);
                    XPathNavigator navConfigMSI = configMSI.CreateNavigator();

                    globalConfigParams.serverAddress  = InstallerClass.DecRijndaelMSI(navConfigMSI.SelectSingleNode("/ConfigParameters/address").ToString()).Replace("\0", String.Empty);
                    globalConfigParams.serverIP       = InstallerClass.DecRijndaelMSI(navConfigMSI.SelectSingleNode("/ConfigParameters/ip").ToString()).Replace("\0", String.Empty);
                    globalConfigParams.textAnalytics  = InstallerClass.DecRijndaelMSI(navConfigMSI.SelectSingleNode("/ConfigParameters/pcenabled").ToString()).Replace("\0", String.Empty);
                    globalConfigParams.aesKey         = InstallerClass.DecRijndaelMSI(navConfigMSI.SelectSingleNode("/ConfigParameters/cryptkey").ToString()).Replace("\0", String.Empty);
                    globalConfigParams.aesIV          = InstallerClass.DecRijndaelMSI(navConfigMSI.SelectSingleNode("/ConfigParameters/cryptkey").ToString()).Replace("\0", String.Empty);
                    globalConfigParams.serverPassword = InstallerClass.DecRijndaelMSI(navConfigMSI.SelectSingleNode("/ConfigParameters/srvpwd").ToString()).Replace("\0", String.Empty);
                    globalConfigParams.excludedApps   = InstallerClass.DecRijndaelMSI(navConfigMSI.SelectSingleNode("/ConfigParameters/apps").ToString()).Replace("\0", String.Empty);

                    SQLStorage db = new SQLStorage();
                    db.CreateDB();

                    Filesystem.WriteLog("INFO : Internal database created from MSI config file");
                }
                else if (!File.Exists(sqliteFile) && !File.Exists(MSIConfigFilePath))
                {
                    Filesystem.WriteLog("ERROR : Internal database and MSI config file doesn't exist, please run MSI Installer");
                    Environment.Exit(0);
                }
                else
                {
                    Filesystem.WriteLog("INFO : User DB3 database found, continue");
                }
            }
            catch (Exception ex)
            {
                Filesystem.WriteLog("ERROR : Exception trown in Database check procedure : " + ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Startup checks
        /// </summary>

        #region Startup checks

        public static void StartupChecks(string entryPoint)
        {
            try
            {
                Filesystem AppSourceFile = new Filesystem(System.Windows.Forms.Application.ExecutablePath);
                string     userSession   = Environment.UserName.ToLower().Replace(" ", string.Empty);

                if (entryPoint == "msi")
                {
                    // Copy executable endpoint to path and protect

                    Filesystem.WriteLog("INFO : Startup check, MSI as argument in app execution");

                    string fromMSIAppPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Software\\" + globalConfigParams.exeName;

                    AppSourceFile.CopyTo(fromMSIAppPath);
                    AppSourceFile = new Filesystem(fromMSIAppPath);
                    AppSourceFile.Protect();

                    Filesystem.WriteLog("INFO : Exiting because it's the first execution");

                    Environment.Exit(0);
                }
                else if (entryPoint == "smoothrun")
                {
                    Filesystem.WriteLog("INFO : Startup check finished, running in smooth");

                    // Store in XML the user database path (for uninstall purposes)

                    string UninstallXMLPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Software\\uninstall.xml";

                    if (File.Exists(UninstallXMLPath))
                    {
                        File.Delete(UninstallXMLPath);
                    }

                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    XmlWriter configWriter = XmlWriter.Create(UninstallXMLPath, settings);
                    configWriter.WriteStartDocument();
                    configWriter.WriteComment("Config file for uninstall purposes");
                    configWriter.WriteStartElement("ConfigParameters");
                    configWriter.WriteElementString("databasepath", InstallerClass.EncRijndaelMSI(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Software\\endpoint.db3"));
                    configWriter.WriteEndElement();
                    configWriter.WriteEndDocument();
                    configWriter.Flush();
                    configWriter.Close();

                    Filesystem.SetFullFilePermissions(UninstallXMLPath);
                }

                if (userSession == "system" || userSession == "administrator" || userSession == "administrador")
                {
                    Environment.Exit(0);
                }
            }
            catch (Exception ex)
            {
                Filesystem.WriteLog("ERROR : Exception trown in Startup Checks : " + ex);
            }
        }