public PrepatchManager() { this._LastKnownLatestVersion = string.Empty; this._isbusy = false; this.syncContext = System.Threading.SynchronizationContext.Current; this.myWebClient = WebClientPool.GetWebClient_PSO2Download(true); this.myFileList = new MemoryFileCollection(); this.bWorker = new BackgroundWorker(); this.bWorker.WorkerReportsProgress = true; this.bWorker.WorkerSupportsCancellation = true; this.bWorker.DoWork += BWorker_DoWork; this.bWorker.RunWorkerCompleted += BWorker_RunWorkerCompleted; }
protected virtual System.Collections.Concurrent.ConcurrentDictionary <string, PSO2File> ParseFilelist(MemoryFileCollection filelist) { Dictionary <string, PSO2File> result = new Dictionary <string, PSO2File>(); if (filelist != null && filelist.Count > 0) { string linebuffer; PSO2File pso2filebuffer; this.ProgressTotal = filelist.Count; this.CurrentStep = LanguageManager.GetMessageText("PSO2UpdateManager_BuildingFileList", "Building file list"); RecyclableMemoryStream rms; for (int i = 0; i < filelist.Count; i++) { rms = filelist[i.ToString()]; // Can't use Using block because in .NET 4.0, StreamReader will also close underlying stream. // We need the RecyclableMemoryStream in tact because we will use it once more later. // According to RecyclableMemoryStream documents, once the RecyclableMemoryStream is closed, all underlying buffer will be returned to the pool //which is why we can't close the stream. // For .NET 4.5 or higher, there is param "keep Open" in the StreamReader constructor which is safe for using block. StreamReader sr = new StreamReader(rms); while (!sr.EndOfStream) { linebuffer = sr.ReadLine(); if (!string.IsNullOrWhiteSpace(linebuffer)) { if (PSO2File.TryParse(linebuffer, DefaultValues.Web.PrecedeDownloadLink, out pso2filebuffer)) { if (!result.ContainsKey(pso2filebuffer.WindowFilename)) { result.Add(pso2filebuffer.WindowFilename, pso2filebuffer); } else { result[pso2filebuffer.WindowFilename] = pso2filebuffer; } } } } this.ProgressCurrent = i + 1; } } return(new System.Collections.Concurrent.ConcurrentDictionary <string, PSO2File>(result)); }
public AddonLoadResult LoadAddon(string path) { AddonLoadResult result = null; string filename = Path.GetFileName(path); using (ZipArchive archive = ZipArchive.Open(path)) using (var reader = archive.ExtractAllEntries()) using (MemoryFileCollection mfc = new MemoryFileCollection()) { RecyclableMemoryStream rms; Leayal.Ini.IniFile ini = null; //seek for the header file while store any files have been read (which are not the header) to memorystream for later use. while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { if (reader.Entry.Key.IsEqual("header.ini", true)) { using (StreamReader sr = new StreamReader(reader.OpenEntryStream())) ini = new Leayal.Ini.IniFile(sr); } else { rms = new RecyclableMemoryStream(reader.Entry.Key, reader.Entry.Size > int.MaxValue ? int.MaxValue : (int)reader.Entry.Size); reader.WriteEntryTo(rms); rms.Position = 0; mfc.Add(reader.Entry.Key, rms); } } } if (ini != null) { try { string req = ini.GetValue("Libraries", "Dependencies", string.Empty); if (!string.IsNullOrWhiteSpace(req)) { string[] reqList = req.Split(','); if (reqList != null && reqList.Length > 0) { for (int i = 0; i < reqList.Length; i++) { AssemblyLoader.myDict.Add(reqList[i], Assembly.Load(mfc[reqList[i]].ToArray())); } } } string mainDll = ini.GetValue("Libraries", "MainLib", string.Empty); if (!string.IsNullOrWhiteSpace(mainDll)) { if (!AssemblyLoader.myDict.ContainsKey(mainDll)) { AssemblyLoader.myDict.Add(mainDll, Assembly.Load(mfc[mainDll].ToArray())); } } result = new AddonLoadResult(filename); } catch (Exception ex) { Leayal.Log.LogManager.GetLogDefaultPath("AddonManager", true).Print(string.Format("Failed to load the add-on in archive '{0}'.\r\n{1}", filename, ex)); result = new AddonLoadResult(filename, ex); } } } return(result); }