public void Add(string FileName, Int64 FileSize, Int64 FileCRC) { PatchFileInfo info = new PatchFileInfo(); info.FileName = FileName; info.FileSize = FileSize; info.FileCRC = FileCRC; PatchFiles.Add(info); }
// 테스트 버튼 - 개발할 때만 사용한다 private void btnTest_Click(object sender, EventArgs e) { List <PatchFileInfo> PatchFileInfoList = new List <PatchFileInfo>(); PatchFileInfo info1 = new PatchFileInfo(); info1.FileName = "dsd1.dsd1"; info1.FileSize = 32323; info1.FileCRC = 3232323; PatchFileInfo info2 = new PatchFileInfo(); info2.FileName = "dsd2.dsd1"; info2.FileSize = 42323; info2.FileCRC = 4232323; PatchFileInfoList.Add(info1); PatchFileInfoList.Add(info2); makePatch.CreatePatchInfoFile(textBoxPackingFilesFolder.Text + "\\" + PATCHINFOFILENAME, 3, PatchFileInfoList); }
// 패치할 파일들을 7zip으로 압축한다 List <PatchFileInfo> PatchFilesCompression_7Zip() { List <PatchFileInfo> PatchFileInfoList = new List <PatchFileInfo>(); PatchFileInfo patchfileinfo = new PatchFileInfo(); // 사용법 // SevenZipSharp 사이트 http://sevenzipsharp.codeplex.com/ try { this.Cursor = Cursors.WaitCursor; string zipName = textBoxPackingFilesFolder.Text + @"\" + PackingFileName + ".7z"; string[] CompressFileNames = GetCompressFileNames(PatchFileList); /// 7Zip 라이브러리를 사용하기 위해서 꼭 7z.dll 파일을 실행파일이 있는 곳에 놓아두고 설정한다 SevenZipCompressor.SetLibraryPath(String.Format(@"{0}\7z.dll", Application.StartupPath)); SevenZipCompressor szc = new SevenZipCompressor(); szc.CompressionMethod = CompressionMethod.Lzma; szc.CompressionMode = SevenZip.CompressionMode.Create; szc.CompressionLevel = CompressionLevel.Normal; szc.CompressFiles(zipName, CompressFileNames); patchfileinfo.FileName = new FileInfo(zipName).Name; patchfileinfo.FileCRC = GetCRC(zipName); patchfileinfo.FileSize = new FileInfo(zipName).Length; PatchFileInfoList.Add(patchfileinfo); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { this.Cursor = Cursors.Default; } return(PatchFileInfoList); }
// 패치할 파일들을 zip 으로 압축한다. List <PatchFileInfo> PatchFilesCompression_Zip() { List <PatchFileInfo> PatchFileInfoList = new List <PatchFileInfo>(); PatchFileInfo patchfileinfo = new PatchFileInfo(); // 사용법 http://dobon.net/vb/dotnet/links/sharpziplib.html // SharpZipLib 사이트 http://www.icsharpcode.net/OpenSource/SharpZipLib/ try { this.Cursor = Cursors.WaitCursor; //ICSharpCode.SharpZipLib.Checksums.Crc32 crc = new ICSharpCode.SharpZipLib.Checksums.Crc32(); string zipFullPathName = textBoxPackingFilesFolder.Text + @"\" + PackingFileName + ".zip"; System.IO.FileStream writer = new System.IO.FileStream(zipFullPathName, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Write); ICSharpCode.SharpZipLib.Zip.ZipOutputStream zos = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(writer); // 압축레벨을 설정 //zos.SetLevel(6); // 패스워드를 설정한다. //zos.Password = "******"; foreach (string file in PatchFileList) { int Substringindex = textBoxNextVerFolder.Text.Length; string f = file.Substring(Substringindex + 1); ICSharpCode.SharpZipLib.Zip.ZipEntry ze = new ICSharpCode.SharpZipLib.Zip.ZipEntry(f); System.IO.FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); fs.Close(); // CRC를 설정한다 //crc.Reset(); //crc.Update(buffer); //ze.Crc = crc.Value; // 사이즈를 설정한다 ze.Size = buffer.Length; // 시간을 설정한다 ze.DateTime = DateTime.Now; // 새로운 파일을 추가 zos.PutNextEntry(ze); // 쓰기 zos.Write(buffer, 0, buffer.Length); } zos.Close(); writer.Close(); patchfileinfo.FileName = new FileInfo(zipFullPathName).Name; patchfileinfo.FileCRC = GetCRC(zipFullPathName); patchfileinfo.FileSize = new FileInfo(zipFullPathName).Length; PatchFileInfoList.Add(patchfileinfo); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { this.Cursor = Cursors.Default; } return(PatchFileInfoList); }