public static bool UpdateCore() { bool bThrewException = false; string LocalModulesList = IgorUtils.DownloadFileForUpdate(IgorModulesListFilename); try { if (File.Exists(LocalModulesList)) { if (File.Exists(InstalledModulesListPath) && HelperDelegates.bIsValid) { IgorUpdater.HelperDelegates.DeleteFile(InstalledModulesListPath); } IgorUpdater.HelperDelegates.CopyFile(LocalModulesList, InstalledModulesListPath); } UpdatedModules.Clear(); if (UpdateModule(CoreModuleName, false)) { return(true); } } catch (TimeoutException to) { if (!File.Exists(LocalModulesList)) { Debug.LogError("Igor Error: Caught exception while self-updating. Exception is " + (to == null ? "NULL exception!" : to.ToString())); bThrewException = true; CleanupTemp(); } } catch (Exception e) { Debug.LogError("Igor Error: Caught exception while updating core. Exception is " + (e == null ? "NULL exception!" : e.ToString())); bThrewException = true; CleanupTemp(); } if (!HelperDelegates.IgorJobConfig_GetWasMenuTriggered()) { if (bThrewException) { Debug.LogError("Igor Error: Exiting EditorApplication because an exception was thrown."); if (HelperDelegates.bIsValid) { EditorApplication.Exit(-1); } } } return(false); }
public static bool UpdateModule(string ModuleName, bool ForceUpdate) { bool bUpdated = false; if (File.Exists(InstalledModulesListPath)) { SharedModuleListInst = IgorModuleList.Load(InstalledModulesListPath); } if (SharedModuleListInst != null) { foreach (IgorModuleList.ModuleItem CurrentModule in SharedModuleListInst.Modules) { if (CurrentModule.ModuleName == ModuleName) { string ModuleDescriptor = IgorUtils.DownloadFileForUpdate(RemoteRelativeModuleRoot + CurrentModule.ModuleDescriptorRelativePath); string CurrentModuleDescriptor = Path.Combine(LocalModuleRoot, CurrentModule.ModuleDescriptorRelativePath); if (File.Exists(ModuleDescriptor)) { IgorModuleDescriptor CurrentModuleDescriptorInst = null; IgorModuleDescriptor NewModuleDescriptorInst = IgorModuleDescriptor.Load(ModuleDescriptor); if (File.Exists(CurrentModuleDescriptor)) { CurrentModuleDescriptorInst = IgorModuleDescriptor.Load(CurrentModuleDescriptor); } if (NewModuleDescriptorInst != null) { if (UpdatedModules.Contains(NewModuleDescriptorInst.ModuleName)) { return(false); } UpdatedModules.Add(NewModuleDescriptorInst.ModuleName); if (NewModuleDescriptorInst.ModuleDependencies.Count > 0) { foreach (string CurrentDependency in NewModuleDescriptorInst.ModuleDependencies) { bUpdated = UpdateModule(CurrentDependency, ForceUpdate) || bUpdated; } } int NewVersion = NewModuleDescriptorInst.ModuleVersion; if (CurrentModuleDescriptorInst == null || NewVersion > CurrentModuleDescriptorInst.ModuleVersion || bAlwaysUpdate || ForceUpdate) { bUpdated = true; UpdatedContent.Add(ModuleName); List <string> FilesToDelete = new List <string>(); if (CurrentModuleDescriptorInst != null) { IgorUpdater.HelperDelegates.DeleteFile(CurrentModuleDescriptor); FilesToDelete.AddRange(CurrentModuleDescriptorInst.ModuleFiles); } if (!Directory.Exists(Path.GetDirectoryName(CurrentModuleDescriptor))) { Directory.CreateDirectory(Path.GetDirectoryName(CurrentModuleDescriptor)); } IgorUpdater.HelperDelegates.CopyFile(ModuleDescriptor, CurrentModuleDescriptor); foreach (string ModuleFile in NewModuleDescriptorInst.ModuleFiles) { FilesToDelete.Remove(ModuleFile); bool bIsExternal = false; string LocalFile = IgorUtils.GetLocalFileFromModuleFilename(ModuleFile); string FullLocalPath = Path.Combine(LocalModuleRoot, Path.Combine(Path.GetDirectoryName(CurrentModule.ModuleDescriptorRelativePath), LocalFile)); string RemotePath = IgorUtils.GetRemoteFileFromModuleFilename(RemoteRelativeModuleRoot + Path.GetDirectoryName(CurrentModule.ModuleDescriptorRelativePath) + "/", ModuleFile, ref bIsExternal); if (LocalFile.StartsWith(".")) { string Base = Path.Combine(LocalModuleRoot.Replace('/', Path.DirectorySeparatorChar), Path.GetDirectoryName(CurrentModule.ModuleDescriptorRelativePath.Replace('/', Path.DirectorySeparatorChar))); string NewLocalFile = LocalFile.Replace('/', Path.DirectorySeparatorChar); int FirstIndex = NewLocalFile.IndexOf(".." + Path.DirectorySeparatorChar); while (FirstIndex != -1) { int LastIndex = Base.LastIndexOf(Path.DirectorySeparatorChar); if (LastIndex != -1) { Base = Base.Substring(0, LastIndex); } NewLocalFile = NewLocalFile.Substring(3); FirstIndex = NewLocalFile.IndexOf(".." + Path.DirectorySeparatorChar); } FullLocalPath = Path.Combine(Base, NewLocalFile); RemotePath = IgorUtils.GetRemoteFileFromModuleFilename(RemoteRelativeModuleRoot + Path.GetDirectoryName(CurrentModule.ModuleDescriptorRelativePath) + "/", ModuleFile, ref bIsExternal); } string TempDownloadPath = ""; if (bIsExternal) { if (!bLocalDownload || bDownloadRemoteWhenLocal || !File.Exists(FullLocalPath)) { if (LocalFile.Contains("../")) { TempDownloadPath = IgorUtils.DownloadFileForUpdate(FullLocalPath, RemotePath); } else { TempDownloadPath = IgorUtils.DownloadFileForUpdate(Path.Combine(Path.GetDirectoryName(CurrentModule.ModuleDescriptorRelativePath), LocalFile), RemotePath); } } } else { TempDownloadPath = IgorUtils.DownloadFileForUpdate(RemotePath); } if (TempDownloadPath != "") { if (File.Exists(FullLocalPath)) { IgorUpdater.HelperDelegates.DeleteFile(FullLocalPath); } if (!Directory.Exists(Path.GetDirectoryName(FullLocalPath))) { Directory.CreateDirectory(Path.GetDirectoryName(FullLocalPath)); } if (File.Exists(TempDownloadPath)) { IgorUpdater.HelperDelegates.CopyFile(TempDownloadPath, FullLocalPath); } } } foreach (string FilenameToDelete in FilesToDelete) { string LocalFile = IgorUtils.GetLocalFileFromModuleFilename(FilenameToDelete); string FullLocalPath = Path.Combine(LocalModuleRoot, Path.Combine(Path.GetDirectoryName(CurrentModule.ModuleDescriptorRelativePath), LocalFile)); if (File.Exists(FullLocalPath)) { IgorUpdater.HelperDelegates.DeleteFile(FullLocalPath); } } } } } return(bUpdated); } } } return(false); }
public static bool SelfUpdate(out bool bMajorUpgrade) { bool bThrewException = false; bMajorUpgrade = false; string InstalledFilePath = Path.Combine(BaseIgorDirectory, IgorUpdaterFilename); try { string LocalUpdater = IgorUtils.DownloadFileForUpdate(IgorUpdaterURL); if (File.Exists(LocalUpdater)) { int NewVersion = GetVersionFromUpdaterFile(LocalUpdater); int NewMajorUpgrade = GetMajorUpgradeFromUpdaterFile(LocalUpdater); if (NewMajorUpgrade > MajorUpgrade) { bMajorUpgrade = true; } if (NewVersion > Version || bAlwaysUpdate) { if (File.Exists(InstalledFilePath)) { IgorUpdater.HelperDelegates.DeleteFile(InstalledFilePath); } if (!Directory.Exists(Path.GetDirectoryName(InstalledFilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(InstalledFilePath)); } IgorUpdater.HelperDelegates.CopyFile(LocalUpdater, InstalledFilePath); return(true); } } } catch (TimeoutException to) { if (!File.Exists(InstalledFilePath)) { Debug.LogError("Igor Error: Caught exception while self-updating. Exception is " + (to == null ? "NULL exception!" : to.ToString())); bThrewException = true; CleanupTemp(); } } catch (Exception e) { Debug.LogError("Igor Error: Caught exception while self-updating. Exception is " + (e == null ? "NULL exception!" : e.ToString())); bThrewException = true; CleanupTemp(); } if (!HelperDelegates.IgorJobConfig_GetWasMenuTriggered()) { if (bThrewException) { Debug.LogError("Igor Error: Exiting EditorApplication because an exception was thrown."); if (HelperDelegates.bIsValid) { EditorApplication.Exit(-1); } } } return(false); }