Exemple #1
0
        /*********************************************************************
         * LoadConfig()
         **********************************************************************/
        private static AppStartConfig LoadConfig()
        {
            AppStartConfig Config;

            //Load the config file which knows where the app lives
            try
            {
                //Try app specific config file name
                Config = AppStartConfig.Load(CalcConfigFileLocation());
                return(Config);
            }
            catch (Exception e)
            {
                try
                {
                    //Try default config file name
                    Debug.WriteLine("APPLICATION STARTER: Falling back to try to read appstart.config.");
                    Config = AppStartConfig.Load(AppDomain.CurrentDomain.BaseDirectory + @"AppStart.Config");
                    return(Config);
                }
                catch
                {
                    HandleTerminalError(e);
                }
            }

            return(null);
        }
Exemple #2
0
        //**************************************************************
        // GetLatestInstalledVersion()
        //**************************************************************
        public static Version GetLatestInstalledVersion()
        {
            //Load the AppStart config File
            string ConfigFilePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            ConfigFilePath = Path.Combine(Directory.GetParent(ConfigFilePath).FullName, "AppStart.config");
            AppStartConfig Config = AppStartConfig.Load(ConfigFilePath);

            AssemblyName AN = AssemblyName.GetAssemblyName(Config.AppExePath);

            return(AN.Version);
        }
Exemple #3
0
        //**************************************************************
        // LoadRemoteConfigFile()
        //**************************************************************
        private static AppStartConfig LoadRemoteConfigFile(string key, string orgConfigPath)
        {
            string NewConfigPath = "";

            try
            {
                RegistryKey r = Registry.LocalMachine.OpenSubKey(key);

                NewConfigPath = (string)r.GetValue("InstallDir");
                NewConfigPath = Path.Combine(NewConfigPath, Path.GetFileName(orgConfigPath));

                return(AppStartConfig.Load(NewConfigPath));
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error loading config file at " + NewConfigPath + " as specified by registry key.");
                throw e;
            }
        }
Exemple #4
0
        //**************************************************************
        // RunThread()
        //**************************************************************
        public void RunThread()
        {
            Debug.WriteLine("APPMANAGER:  Starting Update");

            //Load the AppStart config File
            string ConfigFilePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            ConfigFilePath = Path.Combine(Directory.GetParent(ConfigFilePath).FullName, "AppStart.config");
            Config         = AppStartConfig.Load(ConfigFilePath);

            try
            {
                //Mark in the manifest that a download is in progress.  Persisted in
                //manifest in case the app is stop & restarted during the download.
                if (AppMan.Manifest.State.Phase == UpdatePhases.Complete)
                {
                    AppMan.Manifest.State.Phase = UpdatePhases.Scavenging;
                    AppMan.Manifest.State.UpdateFailureCount      = 0;
                    AppMan.Manifest.State.UpdateFailureEncoutered = false;
                    AppMan.Manifest.State.DownloadDestination     = CreateTempDirectory();

                    if (AppMan.ChangeDetectionMode == ChangeDetectionModes.ServerManifestCheck)
                    {
                        ServerManifest SM = new ServerManifest();
                        SM.Load(AppMan.UpdateUrl);
                        AppMan.Manifest.State.DownloadSource = SM.ApplicationUrl;
                    }
                    else
                    {
                        AppMan.Manifest.State.DownloadSource = AppMan.UpdateUrl;
                    }

                    AppMan.Manifest.Update();
                }

                //Scavenge Existing Directories
                if (AppMan.Manifest.State.Phase == UpdatePhases.Scavenging)
                {
                    Debug.WriteLine("APPMANAGER:  Scavaging older versions");
                    Scavenge();
                    AppMan.Manifest.State.Phase = UpdatePhases.Downloading;
                    AppMan.Manifest.Update();
                }

                //Download the New Version
                if (AppMan.Manifest.State.Phase == UpdatePhases.Downloading)
                {
                    Debug.WriteLine("APPMANAGER:  Downloading new version");
                    Download();
                    AppMan.Manifest.State.Phase = UpdatePhases.Validating;
                    AppMan.Manifest.Update();
                }

                //Validate the downloaded bits
                if (AppMan.Manifest.State.Phase == UpdatePhases.Validating)
                {
                    Debug.WriteLine("APPMANAGER:  Downloading new version");
                    Validate();
                    AppMan.Manifest.State.Phase = UpdatePhases.Merging;
                    AppMan.Manifest.Update();
                }

                //Merge the existing version into the new version
                if (AppMan.Manifest.State.Phase == UpdatePhases.Merging)
                {
                    Debug.WriteLine("APPMANAGER:  Merging current & new versions");
                    MergeDirectory(AppDomain.CurrentDomain.BaseDirectory, AppMan.Manifest.State.DownloadDestination);
                    AppMan.Manifest.State.Phase = UpdatePhases.Finalizing;
                    AppMan.Manifest.Update();
                }

                //Finalize the update.  Rename the new version directory, etc...
                if (AppMan.Manifest.State.Phase == UpdatePhases.Finalizing)
                {
                    Debug.WriteLine("APPMANAGER:  Finalizing update");
                    FinalizeUpdate();
                }

                //Reset Update State
                AppMan.Manifest.State.Phase = UpdatePhases.Complete;
                AppMan.Manifest.State.UpdateFailureCount      = 0;
                AppMan.Manifest.State.UpdateFailureEncoutered = false;
                AppMan.Manifest.State.DownloadSource          = "";
                AppMan.Manifest.State.DownloadDestination     = "";
                AppMan.Manifest.State.NewVersionDirectory     = "";
                AppMan.Manifest.Update();
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
                Debug.WriteLine("APPMANAGER:  ThreadAborted: Updater Thread stopped, stopping download.");
                return;
            }
            catch (Exception e)
            {
                UpdateEventArgs.FailureException = e;
            }

            if (AppMan.Manifest.State.Phase != UpdatePhases.Complete)
            {
                HandleUpdateFailure();
            }
            else
            {
                HandleUpdateSuccess();
            }
        }