private void activateOnlineWorker()
 {
     try
     {
         Activation.ActivateOnline();
         Dispatcher.Invoke(() =>
         {
             ShowActivateResult(true, null);
         });
     }
     catch (Exception exc)
     {
         Dispatcher.Invoke(() =>
         {
             ShowActivateResult(false, exc.Message);
         });
     }
 }
Beispiel #2
0
        private void install()
        {
            try
            {
                Thread.Sleep(Extensions.AnimationDuration.TimeSpan);

                total += files.Count;

                #region Uninstall

                if (InstallerData.InstalledVersion != null &&
                    InstallerData.BackwardsCompatibleTo >= InstallerData.InstalledVersion)
                {
                    total++;
                    step("Uninstalling old version...");

                    // Delete everything
                    InstallerData.DeleteAccounts = InstallerData.DeleteDatabase = InstallerData.DeleteDictionary = InstallerData.DeleteSettings = true;

                    UninstallerWorker uninstall = new UninstallerWorker();
                    uninstall.Uninstall(false);
                }

                #endregion

                #region Files

                step("Creating folders...");

                //
                // File system
                //

                string[] directories = new string[] {
                    "Uninstall",
                    "Resources\\Media",
                    "Resources\\Files",
                    "Themes"
                };

                foreach (string each in directories)
                {
                    Directory.CreateDirectory(InstallerData.InstallLocation + "\\" + each);
                }


                //
                // TODO: Create custom file installations
                //

                //
                // Example
                //

                // File.WriteAllBytes(
                //     InstallerData.InstallLocation + "\\MyProgram.exe",
                //     Properties.Resources.MyProgram
                // );

                foreach (KeyValuePair <string, Lazy <byte[]> > each in files)
                {
                    step("Copying files...");
                    File.WriteAllBytes(InstallerData.InstallLocation + "\\" + each.Key, each.Value.Value);
                }

                step("Copying uninstaller...");
                CopyUninstaller();

                #endregion

                #region Registry

                step("Updating system registry...");
                UpdateRegistry();
                Settings.JoinedCEIP = InstallerData.JoinedCEIP;
                Settings.FirstRun   = false;

                step("Registering product...");

                // Don't reactivate if we are already activated. Otherwise simply installing a new
                // version over an older version of the product will eat product keys.
                if (!Activation.IsActivated(false))
                {
                    if (InstallerData.ProductKey == null)
                    {
                        //
                        // Don't overwrite trial information if it exists.
                        //
                        try
                        {
                            RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\"
                                                                               + GlobalAssemblyInfo.AssemblyName + "\\Activation");
                            object _k = key.GetValue("IDT", null);

                            if (_k == null)
                            {
                                Activation.TrialStart = DateTime.Now;
                            }
                        }
                        catch
                        {
                            Activation.TrialStart = DateTime.Now;
                        }
                    }
                    else
                    {
                        Activation.ActivationGracePeriodStart = DateTime.Now;
                        Activation.Key = InstallerData.ProductKey;

                        try
                        {
                            Activation.ActivateOnline(5);
                            Activation.Activate();
                        }
                        catch { }
                    }
                }

                #endregion

                #region Shortcuts

                step("Installing shortcuts...");

                //
                // TODO: Create shortcuts to applications
                //

                //
                // Example
                //

                // CreateShortcut(
                //     Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\MyProgram.lnk",
                //     InstallerData.InstallLocation + "\\ProductName.exe",
                //     "Click this link to launch MyProgram"
                // );

                //CreateShortcut(InstallerData.ShortcutLocation,
                //	InstallerData.InstallLocation + "\\Daytimer.exe",
                //	InstallerData.Description
                //);
                InstallShortcut();

                #endregion

                step("Optimizing performance for your system...");
                QueueNgen(InstallerData.MainProgramLocation);

                foreach (string each in InstallerData.IncludedAssemblies)
                {
                    QueueNgen(each);
                }

                Complete();
            }
            catch (Exception exc)
            {
                Error(new InstallErrorEventArgs(exc.Message));
            }
        }