Пример #1
0
 public static void SaveDlls(DllModel dll)
 {
     using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
     {
         cnn.Execute("INSERT INTO InstalledDlls (Parent_Id, Name, Type, Version, Entry_Date) VALUES (@Parent_Id, @Name, @Type, @Version, @Entry_Date)", dll);
     }
 }
Пример #2
0
        public void NewInstallThread(string installPath, bool runDBUpdate)
        {
            _form1.DisableInstallButton(false);
            //ProgressBar pb = new ProgressBar();
            //ProgressBar.startingLabel = "Starting...";
            //pb.Show();

            string entryTime = DateTime.Now.ToString();

            //**COPY INSTALLER FROM NETWORK**
            //Thread pb1 = new Thread(() => pb.UpdateProgressBar("Copying installer...", 10));
            //pb1.Start();
            string pathToCopy        = fullInstallerPath;                                                   //  the full path of the installer (path + file name + file extension)
            string installerFileName = Path.GetFileName(pathToCopy);                                        //  the name of the install file (SalesPad.Desktop.Setup.x.x.x.Vers.exe)
            string installerPath     = Path.GetDirectoryName(pathToCopy);                                   //  the path of the installer (no file name or extension)
            string tempInstaller     = Environment.CurrentDirectory + @"\Installers\" + installerFileName;  //  the destination path to copy the selected installer to (EnvMgr\Installers\SalesPad.Desktop.Setup.x.x.x.Vers.exe)

            File.Copy(pathToCopy, tempInstaller, true);

            //**SILENTLY INSTALLING SPGP
            //pb.UpdateProgressBar("Silently Installing SalesPad...", 10);
            Process spgpInstall = new Process();

            spgpInstall.StartInfo.FileName  = tempInstaller;
            spgpInstall.StartInfo.Arguments = @"/S /D=" + installPath;
            spgpInstall.Start();
            spgpInstall.WaitForExit();

            //  WRITE DATABASE PATH TO INSTALLEDBUILD TABLE
            //pb.UpdateProgressBar("Logging build path to InstalledBuild table...", 10);
            BuildModel build = new BuildModel(installerPath, selectedProductVersion, entryTime, "SalesPad GP");

            SqliteDataAccess.SaveBuild(build);

            //  WRITE DATABASE PATH TO LASTINSTALLED TABLE
            //pb.UpdateProgressBar("Logging build path to LastInstalled table...", 10);
            LastInstalledModel lastInstalled = new LastInstalledModel(installPath, "SalesPad GP");

            SqliteDataAccess.SaveBuild(lastInstalled);

            //**DELETING THE INSTALLER
            //pb.UpdateProgressBar("Deleting installer...", 10);
            File.Delete(tempInstaller);

            string        extPath      = installerPath + "\\ExtModules\\" + selectedProductVersion + "\\";
            string        custPath     = installerPath + "\\CustomModules\\" + selectedProductVersion + "\\";
            List <string> custDllToAdd = new List <string>();
            List <string> extDllToAdd  = new List <string>();

            //pb.UpdateProgressBar("Checking for common project modules...", 10);
            //  ADD LIST OF COMMON PROJECT DLLS IF THEIR RESPECTIVE CHECKBOXES ARE CHECKED
            CommonProjectsModules commonProjectsModules = JsonConvert.DeserializeObject <CommonProjectsModules>(File.ReadAllText(Environment.CurrentDirectory + @"\Files\CommonProjectsModules.json"));

            if (checkExpressPointDLLs.Checked)
            {
                custDllToAdd.AddRange(commonProjectsModules.ExpresspointCust);
                extDllToAdd.AddRange(commonProjectsModules.ExpresspointExt);
            }
            if (checkTPGDLLs.Checked)
            {
                custDllToAdd.AddRange(commonProjectsModules.TPGCust);
                extDllToAdd.AddRange(commonProjectsModules.TPGExt);
            }
            if (checkEDIDLL.Checked)
            {
                extDllToAdd.AddRange(commonProjectsModules.EDI);
            }
            if (checkAutomationAgentDLLs.Checked)
            {
                extDllToAdd.AddRange(commonProjectsModules.AutomationAgent);
            }

            //  ADD ANY SELECTED DLLS TO THE LIST
            //pb.UpdateProgressBar("Adding selected dlls to the list...", 10);
            var selectedCustDlls = lbCustomDLLList.SelectedItems;

            foreach (string dll in selectedCustDlls)
            {
                custDllToAdd.Add(dll);
            }
            custDllToAdd.Sort();

            var selectedExtDlls = lbExtendedDLLList.SelectedItems;

            foreach (string dll in selectedExtDlls)
            {
                extDllToAdd.Add(dll);
            }
            extDllToAdd.Sort();

            //  COPY/RECORD DLLS ADDED TO INSTALL
            //pb.UpdateProgressBar("Copying any added dlls to the install folder...", 10);
            if (custDllToAdd.Count > 0)
            {
                foreach (string dll in custDllToAdd.Distinct())
                {
                    string dllName = "SalesPad.Module." + dll + "." + TrimSPVersion(installerPath) + "." + selectedProductVersion.ToUpper();
                    File.Copy(custPath + dllName + ".Zip", Environment.CurrentDirectory + @"\DLLs\SalesPad.Module." + dll + ".Zip", true);
                    DllModel dllModel = new DllModel(SqliteDataAccess.GetLastParentId(), dllName, "Custom DLL", selectedProductVersion, entryTime);
                    SqliteDataAccess.SaveDlls(dllModel);
                }
            }

            if (extDllToAdd.Count > 0)
            {
                foreach (string dll in extDllToAdd.Distinct())
                {
                    string dllName = "SalesPad.Module." + dll + "." + TrimSPVersion(installerPath) + "." + selectedProductVersion.ToUpper();
                    File.Copy(extPath + dllName + ".Zip", Environment.CurrentDirectory + @"\DLLs\SalesPad.Module." + dll + ".Zip", true);
                    DllModel dllModel = new DllModel(SqliteDataAccess.GetLastParentId(), dllName, "Extended DLL", selectedProductVersion, entryTime);
                    SqliteDataAccess.SaveDlls(dllModel);
                }
            }

            //  UNZIP DLLS IF THERE ARE ANY
            //pb.UpdateProgressBar("Unzipping any added dlls...", 10);
            if (custDllToAdd.Count > 0 || extDllToAdd.Count > 0)
            {
                string[] toExtract = Directory.GetFiles(Environment.CurrentDirectory + @"\DLLs");
                foreach (string dll in toExtract)
                {
                    string dllName       = Path.GetFileNameWithoutExtension(dll);
                    string dllTempFolder = Environment.CurrentDirectory + @"\DLLs\" + dllName;
                    Directory.CreateDirectory(dllTempFolder);
                    using (ZipArchive zip = ZipFile.Open(dll, ZipArchiveMode.Read))
                    {
                        try
                        {
                            zip.ExtractToDirectory(dllTempFolder);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(String.Format("An error was encountered while trying to extract {0}. Exception message is as follows:\n\n{1}", dllName, e.Message));
                        }
                        zip.Dispose();
                    }
                    File.Delete(dll);
                }
            }

            foreach (string dir in Directory.GetDirectories(Environment.CurrentDirectory + @"\DLLs\"))
            {
                foreach (string file in Directory.GetFiles(dir))
                {
                    string fileName = Path.GetFileName(file);
                    try
                    {
                        File.Copy(file, String.Format(@"{0}\{1}", installPath, fileName), true);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(String.Format("An error was encountered while trying to copy {0} to {1}. Exception message is as follows:\n\n{2}", fileName, installPath, e.Message));
                    }
                }
                Directory.Delete(dir, true);
            }

            //  RUN DB UPDATE IF SELECTED
            if (runDBUpdate)
            {
                try
                {
                    //pb.UpdateProgressBar("Running the database update...", 5);
                    Process dbUpdate = new Process();
                    dbUpdate.StartInfo.FileName        = installPath + @"\SalesPad.exe";
                    dbUpdate.StartInfo.Arguments       = @"/dbUpdate /userfields /conn=TWO";
                    dbUpdate.StartInfo.UseShellExecute = false;
                    dbUpdate.Start();
                    dbUpdate.WaitForExit();

                    //  LAUNCH THE INSTALLED APPLICATION
                    //pb.UpdateProgressBar("Launching SalesPad...", 5);
                    Process.Start(installPath + @"\SalesPad.exe");
                    if (checkOpenInstallFolder.Checked)
                    {
                        Process.Start(installPath);
                    }
                    _form1.DisableInstallButton(true);
                    return;
                }
                catch (Exception e)
                {
                    MessageBox.Show("This failed:\n\n" + e.ToString());
                }
            }

            //  LAUNCH THE INSTALLED APPLICATION
            //pb.UpdateProgressBar("Launching SalesPad...", 10);
            Process.Start(installPath + @"\SalesPad.exe");
            if (checkOpenInstallFolder.Checked)
            {
                Process.Start(installPath);
            }
            _form1.DisableInstallButton(true);
            //pb.CloseProgressBar();
            return;
        }