Ejemplo n.º 1
0
        /// <summary>
        /// this is usually only used for remote clients; standalone clients are patched with a windows installer program
        /// </summary>
        private static void CheckForPatches()
        {
            FSplashScreen.ProgressText = "Running checks that are specific to Remote Installation...";

            // todo: check whether the user has SYSADMIN rights; should not be required
            // todo: check whether the user has write access to the bin directory
            // check whether the user has access to the server and the Petra patches directory
            if ((TClientSettings.Petra_Path_RemotePatches.Length > 0)
                && !(TClientSettings.Petra_Path_RemotePatches.ToLower().StartsWith("http://")
                     || TClientSettings.Petra_Path_RemotePatches.ToLower().StartsWith("https://"))
                && !System.IO.Directory.Exists(TClientSettings.Petra_Path_RemotePatches))
            {
                FSplashScreen.ShowMessageBox(
                    String.Format(
                        Catalog.GetString(
                            "Please make sure that you have logged in to your network drive\nand can access the directory\n{0}\nIf this is the case and you still get this message,\nyou might use an IP address rather than a hostname for the server.\nPlease ask your local System Administrator for help."),
                        TClientSettings.Petra_Path_RemotePatches),
                    Catalog.GetString("Cannot check for patches"));
            }

            // check whether there is a patch available; if this is a remote version, try to download a patch from the server
            TPatchTools patchTools = new TPatchTools(Path.GetFullPath(TClientSettings.Petra_Path_Bin + Path.DirectorySeparatorChar + ".."),
                TClientSettings.Petra_Path_Bin,
                TPatchTools.OPENPETRA_VERSIONPREFIX,
                TClientSettings.PathTemp,
                "",
                TClientSettings.Petra_Path_Patches,
                TClientSettings.Petra_Path_RemotePatches);

            string PatchStatusMessage;

            // TODO: run this only if necessary. seem adding cost centre does not update the cache?
            TDataCache.ClearAllCaches();

            if (patchTools.CheckForRecentPatch(false, out PatchStatusMessage))
            {
                // todo: display a list of all patches that will be installed? or confusing with different builds?
                if (FSplashScreen.ShowMessageBox(String.Format(Catalog.GetString("There is a new patch available: {0}" +
                                ".\r\nThe currently installed version is {1}" +
                                ".\r\nThe patch will be installed to directory '{2}'.\r\nDo you want to install now?"),
                            patchTools.GetLatestPatchVersion(), patchTools.GetCurrentPatchVersion(), TClientSettings.Petra_Path_Bin),
                        String.Format(Catalog.GetString("Install new OpenPetra patch")), MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                {
                    // reset the caches in IsolatedStorage. This can help if things have changed drastically in the database
                    // TODO: run this also after the software has been reinstalled with the InnoSetup installer? Remember the current patch number in the IsolatedStorage?
                    TDataCache.ClearAllCaches();

                    // create the temp directory; using the Petra tmp directory, so that we don't need to change the drive in the batch file
                    string TempPath = TClientSettings.PathTemp + Path.DirectorySeparatorChar + "petrapatch";
                    Directory.CreateDirectory(TempPath);

                    // check for newer patchtool
                    patchTools.CopyLatestPatchProgram(TempPath);

                    string PatchToolExe = TempPath + Path.DirectorySeparatorChar + "Ict.Tools.PtchTool.exe";

                    if (!File.Exists(PatchToolExe))
                    {
                        TLogging.Log("cannot find file " + PatchToolExe);
                    }

                    // need to stop petra client, start the patch in temppath, restart Petra client
                    Process PatchProcess = new System.Diagnostics.Process();
                    PatchProcess.EnableRaisingEvents = false;
                    PatchProcess.StartInfo.FileName = PatchToolExe;
                    PatchProcess.StartInfo.Arguments = "-action:patchRemote " +
                                                       "-ClientConfig:\"" + Path.GetFullPath(
                        TAppSettingsManager.ConfigFileName) + "\" " +
                                                       "-OpenPetra.Path.Patches:\"" + Path.GetFullPath(
                        TClientSettings.Petra_Path_Bin + "/../patches30") + "\" " +
                                                       "-OpenPetra.PathTemp:\"" + Path.GetFullPath(
                        TClientSettings.Petra_Path_Bin + "/../tmp30") + "\" " +
                                                       "-OpenPetra.Path:\"" + Path.GetFullPath(
                        TClientSettings.Petra_Path_Bin + Path.DirectorySeparatorChar + "..") + "\" " +
                                                       "-OpenPetra.Path.Bin:\"" + Path.GetFullPath(
                        TClientSettings.Petra_Path_Bin) + "\"";
                    PatchProcess.Start();

                    // Application stops here !!!
                    Environment.Exit(0);
                }
            }
            else
            {
                if (PatchStatusMessage != String.Empty)
                {
                    FSplashScreen.ShowMessageBox(PatchStatusMessage, "");
                }
            }
        }