static void Install() { // at this point we're ready to install. ReportProgress(LogLevel.Info, InstallerPhase.Installing, ""); if (m_install_thread.CancellationPending) { return; } string destination_folder = ""; if (m_state.User == InstallerUser.CurrentUser) { // Todo: handle local profile in addition to roaming profile if (SelectedInstaller.InstallRoot == PackageInstallRoot.CurrentUserLocalProfile) { destination_folder = SelectedInstaller.InstallFolder(CurrentUserLocalProfileRoot); } else if (SelectedInstaller.InstallRoot == PackageInstallRoot.CurrentUserRoamingProfile) { destination_folder = SelectedInstaller.InstallFolder(CurrentUserRoamingProfileRoot); } } else if (m_state.User == InstallerUser.AllUsers) { destination_folder = SelectedInstaller.InstallFolder(AllUsersInstallRoot); } else { throw new InstallException("Unrecognized install user: "******"Creating package install folder: " + destination_folder); Directory.CreateDirectory(Path.GetDirectoryName(destination_folder)); // Let package installer do what it wants prior to installation ReportProgress(LogLevel.Debug, InstallerPhase.Installing, "Calling BeforeInstall()"); SelectedInstaller.BeforeInstall(m_package, m_state.RhinoList, m_state.User); // Extract package to final location if (!m_package.Install(destination_folder, SelectedInstaller)) { ReportProgress(LogLevel.Error, InstallerPhase.InstallFailed, "Package installation failed"); return; } // Let package installer clean up after installation if (SelectedInstaller.AfterInstall(m_package, m_state.RhinoList, m_state.User)) { ReportProgress(LogLevel.Info, InstallerPhase.Cleanup, "Deleting temporary files"); DeleteTempFiles(destination_folder); DeleteOldVersions(destination_folder, 2); DeleteTempFolders(); ReportProgress(LogLevel.Info, InstallerPhase.Complete, "INSTALL END: " + m_state.InstallerFilePath); } else { try { DeleteTempFolders(); Directory.Delete(destination_folder, true); ReportProgress(LogLevel.Error, InstallerPhase.InstallFailed, "AfterInstall failed, deleting install directory: " + destination_folder); } catch { // Can't fix it now. ReportProgress(LogLevel.Error, InstallerPhase.InstallFailed, "AfterInstall failed"); } } }
/// <summary> /// Init is called to initialize the package for installation. /// No installation is done, only inspection of the package contents. /// /// 1) Extract .rhi package into temp folder /// 2) Select appropriate PackageInstaller /// 3) Initialize PackageInstaller /// 4) Determine if Package is already installed /// 5) Detect Rhino installations /// 6) Is package compatible with any Rhino installations? /// 7) If all above succeeds, Init succeeded. /// /// All logic for inspection and initialization should be in /// the Package code; not the Engine (the Engine should know /// nothing about installing a specific package). /// </summary> /// <param name="InstallerFilePath"></param> static void Init(string PackagePath) { ReportProgress(LogLevel.Info, InstallerPhase.Initializing, "INIT START: " + m_state.InstallerFilePath); if (!File.Exists(PackagePath)) { ReportProgress(LogLevel.Error, InstallerPhase.InitializationFailed, "Installer Package not Found: '" + PackagePath + "'"); return; } m_package = new Package(PackagePath); m_state.TemporaryFolder = CreateTempFolder(); m_package.DestinationFolder = m_state.TemporaryFolder; if (m_init_thread.CancellationPending) { return; } // 2) Select appropriate PackageInstaller ReportProgress(LogLevel.Info, InstallerPhase.Initializing, "Selecting PackageInstaller"); for (int i = 0; i < m_package_installers.Count; i++) { if (m_package_installers[i].ContainsRecognizedPayload(m_package)) { m_selected_installer_index = i; break; } } if (m_init_thread.CancellationPending) { return; } // No appropriate PackageInstaller found if (SelectedInstaller == null) { ReportProgress(LogLevel.Info, InstallerPhase.InitializationFailed, "Initialization Failed - Appropriate Package Installer Not Found"); return; } // 3) Initialize PackageInstaller ReportProgress(LogLevel.Info, InstallerPhase.Initializing, "Initializing PackageInstaller"); SelectedInstaller.Initialize(m_package); if (m_init_thread.CancellationPending) { return; } // 4) Determine if Package is already installed PackageInstallState install_state = SelectedInstaller.GetInstallState(m_package); if (install_state >= PackageInstallState.SameVersionInstalledCurrentUser) { ReportProgress(LogLevel.Info, InstallerPhase.AlreadyInstalled, "Initialization Complete"); return; } // 5) Detect Rhino installations ReportProgress(LogLevel.Info, InstallerPhase.Initializing, "Detecting Rhino"); DetectInstalledRhino(); if (m_init_thread.CancellationPending) { return; } // 6) Is package compatible with any Rhino installations? foreach (RhinoInfo rhino in m_state.RhinoList) { if (SelectedInstaller.IsCompatible(rhino)) { ReportProgress(LogLevel.Info, InstallerPhase.Initializing, "Found Compatible Rhino"); m_state.CompatibleRhinoIsInstalled = RhinoInstallState.Found; break; } if (m_init_thread.CancellationPending) { return; } } if (m_state.CompatibleRhinoIsInstalled == RhinoInstallState.Found) { ReportProgress(LogLevel.Info, InstallerPhase.Initialized, "Initialization Complete"); } else { ReportProgress(LogLevel.Info, InstallerPhase.InspctPkgNotCompatible, "Initialization Failed - This package is not compatible with any of the Rhino installations on this computer."); } }