public static ListFile parseIgnoreCritical(String line) { var file = new ListFile(); String[] args = line.Split('\t'); file.FileName = args[0]; file.md5Checksum = args[1]; return file; }
public static ListFile parseIgnoreCritical(String line) { var file = new ListFile(); String[] args = line.Split('\t'); file.FileName = args[0]; file.md5Checksum = args[1]; return(file); }
public static ListFile parse(String line) { var file = new ListFile(); String[] args = line.Split('\t'); file.FileName = args[0]; file.Type = (ListFileType)Enum.Parse(typeof(ListFileType), args[1]); file.md5Checksum = args[2]; return file; }
public static ListFile parse(String line) { var file = new ListFile(); String[] args = line.Split('\t'); file.FileName = args[0]; file.Type = (ListFileType)Enum.Parse(typeof(ListFileType), args[1]); file.md5Checksum = args[2]; return(file); }
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); } }
public void UnpackFile(ListFile file) { if (Status == Status.CANCEL) { GoEnd(WordEnum.CANCEL_BY_USER, true); return; } string path = CurrentProperty.Path; string fileName = path + file.FileName.Replace("/", "\\"); FileInfo descFile = new FileInfo(fileName); FileInfo zipFile = new FileInfo(fileName + ".zip"); if (!zipFile.Exists) { GoEnd(WordEnum.PROBLEM_WITH_SERVER, true); return; } MainForm.Instance.UpdateStatusLabel(WordEnum.UNPACKING_S1, zipFile.Name.Replace(".zip", "")); MainForm.Instance.UpdateProgressBar(0, false); ZipInputStream zipStream = new ZipInputStream(zipFile.OpenRead()) { Password = "******" }; ZipEntry fileEntry; byte[] listDate = null; if ((fileEntry = zipStream.GetNextEntry()) != null) { listDate = new byte[zipStream.Length]; zipStream.Read(listDate, 0, listDate.Length); } zipStream.Close(); zipFile.Delete(); //удаляем зип файл descFile.Delete(); //удаляем старый файл if (listDate == null) { GoEnd(WordEnum.PROBLEM_WITH_SERVER, true); return; } Stream stream = descFile.Create(); int size = listDate.Length; int oldPersent = 0; for (int i = 0; i < listDate.Length; i++) { if (Status == Status.CANCEL) { GoEnd(WordEnum.CANCEL_BY_USER, false); break; } stream.WriteByte(listDate[i]); int persent = (int) ((100F*i)/size); if (persent != oldPersent) { oldPersent = persent; MainForm.Instance.UpdateProgressBar(persent, false); } } MainForm.Instance.UpdateProgressBar(100, false); stream.Close(); descFile.LastWriteTime = fileEntry.DateTime; }