private void MainForm_Shown(object sender, EventArgs e) { ShowAllItems(true, true, false); UpdateAllRSS(); UpdateStatusLabel(""); ShowAllItems(false, false, true); CheckInstalled(true); if (RConfig.Instance.CheckVersionOnStart) { TaskManager.Instance.AddTask(AssemblyPage.Instance().ListLoader); } if (RConfig.Instance.CheckCriticalOnStart) { GameProperty p = RConfig.Instance.getGameProperty(RConfig.Instance.ActiveGame); if (!CheckInstalled(false)) { return; } if (!p.ListLoader.IsValid) { TaskManager.Instance.AddTask(p.ListLoader); } TaskManager.Instance.AddTask(new AnalyzerTask(p, ListFileType.CRITICAL)); } }
private void GoEnd(WordEnum word) { Status = Status.FREE; AssemblyPage.Instance().UpdateStatusLabel(word, false); // if (!(TaskManager.Instance.NextTask() is AnalyzerTask)) { AssemblyPage.Instance().SetState(MainFormState.NONE); MainForm.Instance.SetMainFormState(MainFormState.NONE); } OnEnd(); }
private void ListDownloadThread() { if (Status != Status.FREE || _webClient.IsBusy) { return; } AssemblyPage.Instance().UpdateStatusLabel(WordEnum.STARTING_DOWNLOAD_LIST, true); AssemblyPage.Instance().SetState(MainFormState.CHECKING); MainForm.Instance.SetMainFormState(MainFormState.CHECKING); Status = Status.DOWNLOAD; IsValid = false; _webClient.DownloadDataAsync(new Uri("http://jdevelopstation.com/awlauncher/list.zip")); }
public PropertyForm() { InitializeComponent(); //1 вкладка главные настройки _generalPage = new TabPage(LanguageHolder.Instance()[WordEnum.GENERAL]); var ppage = new PropertyPage(RConfig.Instance) { Location = new Point(3, 3) }; _generalPage.Controls.Add(ppage); _tabs.TabPages.Add(_generalPage); foreach (var enu in Enum.GetValues(typeof(Game))) { var gpage = new TabPage(GameInfo.getNameOf(enu)); var gp = RConfig.Instance.getGameProperty((Game)enu); var gppage = new PropertyPage(gp) { Location = new Point(3, 3), Enabled = gp.isEnable() }; gpage.Controls.Add(gppage); _tabs.TabPages.Add(gpage); } _versionControlPage = new TabPage(LanguageHolder.Instance()[WordEnum.VERSION_CONTROL]); var assemblyPage = AssemblyPage.Instance(); assemblyPage.Location = new Point(3, 3); _versionControlPage.Controls.Add(assemblyPage); _tabs.TabPages.Add(_versionControlPage); Shown += PropertyForm_Shown; }
private void GoEnd(WordEnum word, bool free, params Object[] aa) { if (free) { Status = Status.FREE; } if (word == WordEnum.UPDATE_DONE) { AssemblyPage.Instance().SetState(MainFormState.DONE); } else { AssemblyPage.Instance().SetState(MainFormState.NONE); } AssemblyPage.Instance().UpdateStatusLabel(String.Format(LanguageHolder.Instance()[word], aa), false); AssemblyPage.Instance().UpdateProgressBar(0, false); AssemblyPage.Instance().UpdateProgressBar(0, true); OnEnd(); }
private void AnalizeToThread() { if (!AssemblyPage.Instance().ListLoader.IsValid) { return; } AssemblyPage.Instance().SetState(MainFormState.CHECKING); AssemblyPage.Instance().UpdateProgressBar(0, true); AssemblyPage.Instance().UpdateProgressBar(0, false); Status = Status.DOWNLOAD; foreach (ListFile listFile in AssemblyPage.Instance().ListLoader.Items) { _temp.AddLast(listFile); } _maxSize = _temp.Count; CheckNextFile(); }
private void PropertyForm_Shown(object sender, EventArgs e) { AssemblyPage.Instance().SetVersionTypeU(MainForm.Instance.Version, MainForm.Instance.VersionType); _oldLanguage = RConfig.Instance.Language; if (SystemInfo.Instance.isGlassEnable) { DWMApi.DwmExtendFrameIntoClientArea(Handle, _margins); /* DWMApi.WTA_OPTIONS ops = new DWMApi.WTA_OPTIONS * { * Flags = DWMApi.WTNCA_NODRAWCAPTION | DWMApi.WTNCA_NODRAWICON, * Mask = DWMApi.WTNCA_NODRAWCAPTION | DWMApi.WTNCA_NODRAWICON * }; * * DWMApi.SetWindowThemeAttribute(Handle, * DWMApi.WindowThemeAttributeType.WTA_NONCLIENT, * ref ops, * (uint)Marshal.SizeOf(typeof(DWMApi.WTA_OPTIONS)));*/ } }
public void CheckNextFile() { if (Status == Status.CANCEL) { GoEnd(WordEnum.CANCEL_BY_USER, true); return; } ListFile file = FirstFile(); if (file == null) { GoEnd(WordEnum.UPDATE_DONE, true); return; } int currentCount = _maxSize - _temp.Count; var persent = (int)((100F * (currentCount)) / _maxSize); AssemblyPage.Instance().UpdateProgressBar(persent, true); string path = Directory.GetCurrentDirectory(); string fileName = path + file.FileName.Replace("/", "\\"); var info = new FileInfo(fileName); string word = LanguageHolder.Instance()[WordEnum.CHECKING_S1]; AssemblyPage.Instance().UpdateStatusLabel(String.Format(word, info.Name.Replace(".zip", "")), true); /* if (FileUtils.IsFileOpen(info)) * { * GoEnd(WordEnum.FILE_S1_IS_OPENED_UPDATE_CANCEL, true, info.Name.Replace(".zip", "")); * return; * }*/ String checkSum; try { checkSum = DTHasher.GetMD5Hash(fileName); } catch (Exception) { try { info.Delete(); } catch {} GoEnd(WordEnum.FILE_S1_IS_PROBLEMATIC_UPDATE_CANCEL_PLEASE_RECHECK, true, info.Name.Replace(".zip", "")); return; } if (checkSum == null) { GoEnd(WordEnum.PROBLEM_WITH_SERVER, true); return; } if (!info.Exists) { DownloadFile(file); //грузим } else if (!checkSum.Equals(file.md5Checksum)) //файл не совпадает { DownloadFile(file); //грузим } else { _temp.Remove(file); CheckNextFile(); //идем дальше } }
public void UnpackFile(ListFile file) { if (Status == Status.CANCEL) { GoEnd(WordEnum.CANCEL_BY_USER, true); return; } string path = Directory.GetCurrentDirectory(); string fileName = path + file.FileName.Replace("/", "\\"); // var descFile = new FileInfo(fileName); var newFile = new FileInfo(fileName + ".new"); string word = LanguageHolder.Instance()[WordEnum.UNPACKING_S1]; AssemblyPage.Instance().UpdateStatusLabel(String.Format(word, newFile.Name.Replace(".new", "")), true); AssemblyPage.Instance().UpdateProgressBar(0, false); var zipStream = new ZipInputStream(newFile.OpenRead()); ZipEntry fileEntry; byte[] bytes = null; if ((fileEntry = zipStream.GetNextEntry()) != null) { bytes = new byte[zipStream.Length]; zipStream.Read(bytes, 0, bytes.Length); } zipStream.Close(); newFile.Delete(); //удаляем зип файл // descFile.Delete(); //удаляем старый файл if (bytes == null) { GoEnd(WordEnum.PROBLEM_WITH_SERVER, true); return; } FileStream fileStream = newFile.Create(); int size = bytes.Length; int oldPersent = 0; for (int i = 0; i < bytes.Length; i++) { if (Status == Status.CANCEL) { GoEnd(WordEnum.CANCEL_BY_USER, false); break; } fileStream.WriteByte(bytes[i]); var persent = (int)((100F * i) / size); if (persent != oldPersent) { oldPersent = persent; AssemblyPage.Instance().UpdateProgressBar(persent, false); } } AssemblyPage.Instance().UpdateProgressBar(100, false); fileStream.Close(); newFile.LastWriteTime = fileEntry.DateTime; _temp.Remove(file); CheckNextFile(); }
public void DownloadFile(ListFile file) { if (Status == Status.CANCEL) { GoEnd(WordEnum.CANCEL_BY_USER, true); return; } string path = Directory.GetCurrentDirectory(); string fileName = path + file.FileName.Replace("/", "\\") + ".new"; var url = new Uri("http://jdevelopstation.com/awlauncher" + file.FileName + ".zip"); var info = new FileInfo(fileName); if (info.Directory != null) { if (!info.Directory.Exists) { info.Directory.Create(); } } var request = (HttpWebRequest)WebRequest.Create(url); var response = (HttpWebResponse)request.GetResponse(); response.Close(); long iSize = response.ContentLength; int iRunningByteTotal = 0; var client = new WebClient(); Stream remoteStream; try { remoteStream = client.OpenRead(url); } catch (WebException) { GoEnd(WordEnum.PROBLEM_WITH_INTERNET, true); return; } catch (Exception) { GoEnd(WordEnum.PROBLEM_WITH_SERVER, true); return; } var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None); var byteBuffer = new byte[8192]; string word = LanguageHolder.Instance()[WordEnum.DOWNLOADING_S1]; AssemblyPage.Instance().UpdateStatusLabel(String.Format(word, info.Name.Replace(".zip", "")), true); bool exception = false; try { int oldPersent = 0; int iByteSize; while ((iByteSize = remoteStream.Read(byteBuffer, 0, byteBuffer.Length)) > 0) { if (Status == Status.CANCEL) { GoEnd(WordEnum.CANCEL_BY_USER, false); break; } fileStream.Write(byteBuffer, 0, iByteSize); iRunningByteTotal += iByteSize; var persent = (int)((100F * iRunningByteTotal) / iSize); if (persent != oldPersent) { oldPersent = persent; AssemblyPage.Instance().UpdateProgressBar(persent, false); } } } catch (WebException) { exception = true; GoEnd(WordEnum.PROBLEM_WITH_INTERNET, true); } catch (Exception) { exception = true; GoEnd(WordEnum.PROBLEM_WITH_SERVER, true); } remoteStream.Close(); fileStream.Close(); if (!exception) { UnpackFile(file); } }
/// <summary> /// С текущего масива грузит список файлов /// </summary> /// <param name="zipArray"></param> private void GoNextStep(byte[] zipArray) { var zipStream = new ZipInputStream(new MemoryStream(zipArray)) { Password = "******" }; byte[] array = null; if ((zipStream.GetNextEntry()) != null) { array = new byte[zipStream.Length]; zipStream.Read(array, 0, array.Length); } zipStream.Close(); if (array == null) { GoEnd(WordEnum.PROBLEM_WITH_SERVER); return; } string encodingBytes = Encoding.UTF8.GetString(array); string[] lines = encodingBytes.Split('\n'); foreach (string line in lines) { if (line.Trim().Equals("")) { continue; } if (Status == Status.CANCEL) { GoEnd(WordEnum.CANCEL_BY_USER); return; } if (line.StartsWith("#Version:")) { String ver = line.Replace("#Version:", "").Trim(); VersionType v = AssemblyPage.CalcType(ver); MainForm.Instance.SetVersionType(ver, v); AssemblyPage.Instance().SetVersionType(ver, v); continue; } if (line.StartsWith("#")) { continue; } try { ListFile file = ListFile.parseIgnoreCritical((line)); _items.AddLast(file); } catch (Exception e) { _log.Info("Exception for line " + line + " " + e, e); } } IsValid = true; GoEnd(WordEnum.ENDING_DOWNLOAD_LIST); }