public void DownloadSchema() { try { WebClient client = new WebClient(); string content = client.DownloadString(@"http://potm.markjohansen.dk/content/packages.xml"); XmlSerializer serializer = new XmlSerializer(typeof(Collection)); using (StringReader reader = new StringReader(content)) { _collections = (Collection)serializer.Deserialize(reader); } } catch (Exception ex) { } }
public void BuildFiles() { //check if the updatepath is set and if the directory exists. if (_updatePath != null && Directory.Exists(_updatePath)) { //clear our the information _collections = new Collection(); //asdasd if (!Directory.Exists(_updatePath + "\\output")) { Directory.CreateDirectory(_updatePath+"\\output"); } //get the directory information DirectoryInfo directory = new DirectoryInfo(_updatePath); //get the dir length int dirLength = _updatePath.Length; //run though each folder foreach (DirectoryInfo d in directory.GetDirectories()) { if (d.Name != "output") { //ask the collection to find the files FileCollection c = FileCollection.Build(d); //run though each files foreach (FileItem f in c.Files) { //initiate a CRC object CRC32 crc = new CRC32(); //build the stringname string FullPath = _updatePath + "\\" + c.Name + f.Directory + f.Filename; //write Console.WriteLine("[FILE] : " + FullPath); //open a link to the file using (Stream reader = new FileStream(FullPath, FileMode.Open, FileAccess.Read)) { //go though each byte foreach (byte b in crc.ComputeHash(reader)) { //build the crc string f.FileCRC += b.ToString("x2").ToLower(); } } //write Console.WriteLine("[FILE-CRC] : " + f.FileCRC); //output file string outputDir = _updatePath + "\\output" + f.Directory; string outputFile = outputDir + f.Filename + ".7z"; Directory.CreateDirectory(outputDir); //start archiving the file SevenZipCompressor.SetLibraryPath("7z.dll"); SevenZipCompressor zip = new SevenZipCompressor(); zip.CompressionMethod = CompressionMethod.Lzma2; zip.CompressionLevel = CompressionLevel.Ultra; zip.CompressionMode = CompressionMode.Create; Console.WriteLine("[COMPRESS-FROM] : " + FullPath); Console.WriteLine("[COMPRESS-TO] : " + outputDir + f.Filename + ".7z"); zip.CompressFiles(outputFile, FullPath); //initiate a CRC object CRC32 crc2 = new CRC32(); f.ArchiveCRC = ""; //open a link to the file using (Stream reader = new FileStream(outputFile, FileMode.Open, FileAccess.Read)) { //go though each byte foreach (byte b in crc2.ComputeHash(reader)) { //build the crc string f.ArchiveCRC += b.ToString("x2").ToLower(); } } Console.WriteLine("[ARCHIVE-CRC] : " + f.ArchiveCRC); Console.WriteLine(); } //add the collection to the group _collections.Collections.Add(c); } } XmlSerializer serializer = new XmlSerializer(typeof(Collection)); using (Stream stream = File.OpenWrite(_updatePath+@"\output\packages.xml")) { serializer.Serialize(stream, _collections); } } }