public PublishPackage(IConfig config, [NotNull] string tempDir, [NotNull] IOutput output) { if (tempDir == null) { throw new ArgumentNullException("tempDir"); } if (output == null) { throw new ArgumentNullException("output"); } this.tempDir = tempDir; this.output = output; var buildCode = config.GetValue("build code"); var buildNumber = config.GetValue("build number"); releasesInfoPath = config.GetValue("releases info path"); packageBinPath = config.GetValue("package bin path"); webServiceRootUrl = config.GetValue("web service root url"); webServiceControllerPath = config.GetValue("web service controller path"); webServiceLogin = config.GetValue("web service login"); webServicePassword = config.GetValue("web service password"); slackIntegrationSubUrl = config.GetValue("slack integration sub url"); var latestMinorVersionString = GetLatestMinorVersionString(); version = new Wa3VersionInfo( buildCode, buildNumber, latestMinorVersionString, DateTimeOffset.Now); }
public IEnumerable <Wa3VersionInfo> GetInstalledVersions() { return (new DirectoryInfo(installDirPath) .EnumerateDirectories() .Select( info => { try { var version = Wa3VersionInfo.CreateFromVersionDat( File.ReadAllText( Path.Combine(info.FullName, "version.dat").Trim())); if (version.BuildNumber != info.Name) { gui.AddUserMessage("Version does not match directory name", Color.Orange); return null; } return version; } catch (Exception exception) { gui.AddUserMessage("Version parsing failed, error: " + exception.Message, Color.Orange); return null; } }) .Where(info => info != null)); }
public WaVersion([NotNull] IBinDirectory binDirectory, [NotNull] ILogger logger) { if (binDirectory == null) { throw new ArgumentNullException("binDirectory"); } if (logger == null) { throw new ArgumentNullException("logger"); } this.binDirectory = binDirectory; this.logger = logger; try { var filePath = Path.Combine(binDirectory.FullPath, "version.dat"); if (!File.Exists(filePath)) { logger.Warn($"version.dat does not exist at {filePath}. Is this development build?"); } else { var fileContent = File.ReadAllText(filePath); var version = Wa3VersionInfo.CreateFromVersionDat(fileContent); logger.Info("Parsed WA version: " + version); VersionInfo = version; } } catch (Exception exception) { logger.Error(exception, "Error at parsing WA version information"); } }
async Task Run() { bool wasError = false; Modules.Launcher launcher = null; IInstallLocation installLocation = null; try { UpdateSourceUpdater updateSourceUpdater = new UpdateSourceUpdater(new WurmAssistantService(Settings.Default.WurmAssistantUpdateSourceUrl), settings); var updateSourceUpdaterTask = updateSourceUpdater.FetchUpdateSourceHost(); // if first run ever, first establish... if (!settings.UpdateSourceEstablished) { gui.AddUserMessage("First run, establishing update source url"); await updateSourceUpdaterTask; updateSourceUpdater.CommitUpdatedSourceHost(); config.WebServiceRootUrl = settings.WurmAssistantWebServiceUrl; settings.UpdateSourceEstablished = true; gui.AddUserMessage("Update source url established to: " + settings.WurmAssistantWebServiceUrl); } launcher = new Modules.Launcher(config); installLocation = new InstallLocation(config, new ProcessRunner(), gui); launcher.EnterLock(); IStagingLocation stagingLocation = new StagingLocation(config); IUpdateService updateService = new UpdateService(config, stagingLocation); stagingLocation.ClearExtractionDir(); stagingLocation.ClearStagingArea(); gui.ShowGui(); Wa3VersionInfo localVersion; Wa3VersionInfo targetVersion = null; if (config.BuildNumber != null) { targetVersion = new Wa3VersionInfo(config.BuildCode, config.BuildNumber); localVersion = installLocation.GetInstalledVersions() .FirstOrDefault(info => info.BuildNumber == targetVersion.BuildNumber); if (localVersion != null) { gui.EnableSkip(); gui.SkipAction = () => { TryRunWurmAssistant(installLocation, localVersion.BuildNumber); }; } } else { localVersion = installLocation.TryGetLatestInstalledVersion(); if (installLocation.AnyInstalled) { gui.EnableSkip(); gui.SkipAction = () => { TryRunWurmAssistant(installLocation, localVersion.BuildNumber); }; } gui.AddUserMessage("Local version is: " + (localVersion != null ? localVersion.ToString() : "None")); try { var latestBuildNumber = await updateService.GetLatestVersionAsync(gui, config.BuildCode); if (!string.IsNullOrEmpty(latestBuildNumber)) { targetVersion = new Wa3VersionInfo(config.BuildCode, latestBuildNumber); } else { wasError = true; gui.AddUserMessage(string.Format("No build found for build code: {0}", config.BuildCode), Color.Red); } } catch (Exception exception) { wasError = true; var template = "Launcher failed to check latest WA version of build {0}. Error: {1}"; gui.AddUserMessage(string.Format(template, config.BuildCode, exception.ToStringMessagesOnly()), Color.Red); debug.Write(string.Format(template, config.BuildCode, exception.ToString())); } } if (targetVersion == null) { // skip } else if (localVersion == targetVersion) { gui.AddUserMessage("Target version is already installed."); } else { try { gui.AddUserMessage("Downloading..."); gui.SetProgressStatus("Downloading..."); var package = await updateService.GetPackageAsync(gui, targetVersion.BuildCode, targetVersion.BuildNumber); gui.AddUserMessage("Installing..."); gui.SetProgressStatus("Installing..."); gui.SetProgressPercent(null); stagingLocation.ExtractIntoExtractionDir(package); stagingLocation.ClearStagingArea(); stagingLocation.MoveExtractionDir(Path.Combine(installLocation.InstallLocationPath, targetVersion.BuildNumber)); gui.AddUserMessage("installed version: " + installLocation.TryGetLatestInstalledVersion().ToString()); gui.AddUserMessage("Update complete"); gui.SetProgressStatus("Update complete"); } catch (Exception exception) { wasError = true; var template = "Launcher failed to download or install WA3 version {0} of build {1}. Error: {2}"; gui.AddUserMessage( string.Format(template, targetVersion, config.BuildCode, exception.ToStringMessagesOnly()), Color.Red); debug.Write(string.Format(template, targetVersion, config.BuildCode, exception.ToString())); } } await Task.Delay(TimeSpan.FromSeconds(1)); if (targetVersion != null) { if (!TryRunWurmAssistant(installLocation, targetVersion.BuildNumber)) { gui.AddUserMessage("Could not start WA for version: " + targetVersion); wasError = true; } } else if (localVersion != null) { if (!TryRunWurmAssistant(installLocation, localVersion.BuildNumber)) { gui.AddUserMessage("Could not start WA for version: " + localVersion); wasError = true; } } if (!wasError) { gui.HideGui(); host.Close(); } else { gui.SetState(LauncherState.Error); } await updateSourceUpdaterTask; updateSourceUpdater.CommitUpdatedSourceHost(); } catch (LockFailedException exception) { debug.Write("LockFailedException: " + exception.ToString()); gui.AddUserMessage("LockFailedException: " + exception.ToStringMessagesOnly(), Color.Red); gui.SetState(LauncherState.Error); } finally { if (launcher != null) { launcher.ReleaseLock(); } } }