/// <summary> /// Searches the mod archive for a AVC Plugin version file and reads it. /// </summary> /// <param name="fullpath">The path to the mod archive.</param> /// <returns>The AVCInfos from the AVC Plugin version file or null if no such file was found.</returns> private static AVCInfo TryReadAVCVersionFile(string fullpath) { string fileContent = string.Empty; try { if (File.Exists(fullpath)) { using (IArchive archiv = ArchiveFactory.Open(fullpath)) { foreach (IArchiveEntry entry in archiv.Entries) { if (entry.IsDirectory) { continue; } if (entry.FilePath.EndsWith(AVC_VERSION_FILE_EXTENSION, StringComparison.CurrentCultureIgnoreCase)) { Messenger.AddDebug(string.Format(Messages.MSG_AVC_VERSIONFILE_FOUND)); using (MemoryStream memStream = new MemoryStream()) { entry.WriteTo(memStream); memStream.Position = 0; StreamReader reader = new StreamReader(memStream); fileContent = reader.ReadToEnd(); break; } } } if (string.IsNullOrEmpty(fileContent)) { Messenger.AddDebug(string.Format(Messages.MSG_NO_AVC_VERSIONFILE_FOUND)); } } } else { Messenger.AddInfo(string.Format(Messages.MSG_FILE_NOT_FOUND_0, fullpath)); } if (!string.IsNullOrEmpty(fileContent)) { Messenger.AddDebug(string.Format(Messages.MSG_READING_AVC_VERSIONFILE_INFO)); return(AVCParser.ReadFromString(fileContent)); } } catch (Exception ex) { Messenger.AddError(Messages.MSG_ERROR_WHILE_READING_AVC_VERION_FILE, ex); } return(null); }
/// <summary> /// Copies Infos to the ModInfo. /// Try to find a compatible SiteHandler for the provided urls (like Download, URL, ChangeLogUrl, GitHub) /// </summary> private static void ImportAvcInfo(AVCInfo avcInfo, ref ModInfo modInfo) { Messenger.AddDebug(string.Format(Messages.MSG_IMPORTING_AVC_VERSIONFILE_INFO_0, modInfo.Name)); string fileName = Path.GetFileNameWithoutExtension(modInfo.LocalPath); if (!OptionsController.AVCIgnoreName && !string.IsNullOrEmpty(avcInfo.Name) && (string.IsNullOrEmpty(modInfo.Name) || modInfo.Name == fileName)) { modInfo.Name = avcInfo.Name; } if (!string.IsNullOrEmpty(avcInfo.Version) && (string.IsNullOrEmpty(modInfo.Version))) { modInfo.Version = avcInfo.Version; } if (!string.IsNullOrEmpty(avcInfo.KspVersion) && (string.IsNullOrEmpty(modInfo.KSPVersion))) { modInfo.KSPVersion = avcInfo.KspVersion; } if (!OptionsController.AVCIgnoreURL && !string.IsNullOrEmpty(avcInfo.Url) && (string.IsNullOrEmpty(modInfo.AvcURL))) { AVCInfo newAvcInfo = null; try { // Get newest AVC informations for this mod. newAvcInfo = AVCParser.ReadFromWeb(avcInfo.Url); } catch (Exception ex) { Messenger.AddError(string.Format(Messages.MSG_ERROR_DOWNLOADING_NEW_AVC_VERION_FILE_FAILED), ex); } if (newAvcInfo != null) { modInfo.AvcURL = avcInfo.Url; avcInfo.Download = newAvcInfo.Download; avcInfo.ChangeLog = newAvcInfo.ChangeLog; avcInfo.ChangeLogUrl = newAvcInfo.ChangeLogUrl; avcInfo.GitHubUsername = newAvcInfo.GitHubUsername; avcInfo.GitHubRepository = newAvcInfo.GitHubRepository; avcInfo.GitHubAllowPreRelease = newAvcInfo.GitHubAllowPreRelease; } } if (string.IsNullOrEmpty(modInfo.ModURL) && !modInfo.HasSiteHandler) { ISiteHandler siteHandler = null; string downloadUrl = string.Empty; string[] urls = new[] { GitHubHandler.GetProjectUrl(avcInfo.GitHubUsername, avcInfo.GitHubRepository), avcInfo.Download, avcInfo.Url, avcInfo.ChangeLogUrl }; foreach (string url in urls) { downloadUrl = url; siteHandler = SiteHandlerManager.GetSiteHandlerByURL(downloadUrl); if (siteHandler != null) { break; } } if (siteHandler != null) { modInfo.ModURL = downloadUrl; modInfo.SiteHandlerName = siteHandler.Name; Messenger.AddDebug(string.Format(Messages.MSG_COMPATIBLE_SITEHANDLER_0_FOUND_1, siteHandler.Name, modInfo.Name)); } else { Messenger.AddDebug(string.Format(Messages.MSG_NO_COMPATIBLE_SITEHANDLER_FOUND_0, modInfo.Name)); } } }