Advertisement
Guest User

compile

a guest
Apr 9th, 2011
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.84 KB | None | 0 0
  1.         private void Compile()
  2.         {
  3.             Crc32 crc32 = new Crc32();
  4.  
  5.             int FullFileProgress = 0;
  6.             bool FulFileExist = false;
  7.             bool CriticalExist = true;
  8.  
  9.             if (CL.Count <= 0)
  10.                 CriticalExist = false;
  11.  
  12.             if (CriticalExist)
  13.             {
  14.                 ShowMsgProgress("Kritische Dateien werden aktualisiert.");
  15.             }
  16.             ShowMsgProgress("Zum Schreiben crt.cy öffnen.");
  17.  
  18.             FileStream fsCU = new FileStream(PathTo + "\\bin32\\crt.cy", FileMode.Open, FileAccess.Write);
  19.             StreamWriter sCU = new StreamWriter(fsCU);
  20.  
  21.  
  22.             ShowMsgProgress("Zum Schreiben fll.cy öffnen.");
  23.  
  24.             FileStream fsFU = new FileStream(PathTo + "\\bin32\\fll.cy", FileMode.Open, FileAccess.Write);
  25.             StreamWriter sFU = new StreamWriter(fsFU);
  26.  
  27.             ShowMsgProgress("Suche nach _fll.cy");
  28.             if (File.Exists(PathTo + "\\bin32\\_fll.cy"))
  29.                 FulFileExist = true;
  30.  
  31.             if (FulFileExist)
  32.             {
  33.                 ShowMsgProgress("Datei eines älteren Backups gefunden!");
  34.                 ShowMsgProgress("Für ein erfolgreiches Update bitte überprüfen.");            
  35.             }
  36.  
  37.             ShowMsgProgress("Erster Schritt");
  38.             DirectoryInfo diFromDir = new DirectoryInfo(@PathClient);
  39.             DirectoryInfo[] diFromArr = diFromDir.GetDirectories();
  40.  
  41.             foreach (DirectoryInfo DirName in diFromArr)
  42.             {
  43.                 DirectoryInfo fFromDir = new DirectoryInfo(@PathClient + "/" + DirName);
  44.  
  45.                 ShowMsgProgress("Lese Verzeichnis: " + DirName);
  46.  
  47.                 foreach (FileInfo Fname in fFromDir.GetFiles())
  48.                 {
  49.  
  50.                     //params
  51.                     bool ToZip = true;
  52.  
  53.                     UpdateFileProgress(0);
  54.  
  55.                     ShowMsgProgress("Überprüfe Update-Verzeichnis: " + DirName);
  56.                     if (!System.IO.Directory.Exists(PathTo + "\\" + DirName))
  57.                     {
  58.                        
  59.                         ShowMsgProgress("Ordner nicht Vorhanden. Erstelle Ordner: " + DirName);
  60.                         System.IO.Directory.CreateDirectory(PathTo + "\\" + DirName);
  61.                     }
  62.  
  63.                     ShowMsgProgress("Status: " + Fname);
  64.                    
  65.                     string FileHash = crc32.Get(PathClient + "\\" + DirName + "\\" + Fname);
  66.  
  67.                     if (FulFileExist)
  68.                     {
  69.                         string line;
  70.  
  71.                         StreamReader readLastAllFile = new StreamReader(@PathTo + "\\bin32\\_fll.cy");
  72.                         //readLastAllFile.
  73.                         while ((line = readLastAllFile.ReadLine()) != null)
  74.                         {
  75.                             string[] sLine = line.Split(delimeter, StringSplitOptions.RemoveEmptyEntries);
  76.                             if (sLine[0].Trim() == DirName+"\\"+Fname)
  77.                             {
  78.                                 if (File.Exists(PathTo + "\\" + sLine[0] + ".zip"))
  79.                                 {
  80.                                     ShowMsgProgress("Datei: " + Fname + " wird bereits aktualisiert.");
  81.                                     ShowMsgProgress("Prüfe Datei: " + Fname + " auf Veränderungen.");
  82.  
  83.                                     if (FileHash == sLine[2].Trim() && sLine[4].Trim() == crc32.Get(PathTo + "\\" + sLine[0] + ".zip"))
  84.                                     {
  85.                                         ShowMsgProgress("Hash von: " + Fname + " stimmt mit dem Original überein. Überspringe.");
  86.                                         ToZip = false;
  87.                                     }
  88.                                 }
  89.                             }
  90.                         }
  91.                         readLastAllFile.Close();
  92.                     }
  93.  
  94.                     if (ToZip)
  95.                     {
  96.                         ShowMsgProgress("Archivierungsdatei: " + PathClient + "\\" + DirName + "\\" + Fname);
  97.                         using (ZipFile zip = new ZipFile()) // Erstelle Archiv
  98.                         {
  99.                             zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression; // Kompressionsgrad
  100.                             zip.AddFile(@PathClient + "\\" + DirName + "\\" + Fname, "");
  101.                             zip.Save(@PathTo + "\\" + DirName + "\\" + Fname + ".zip"); // erstelle Sicherungskopie                            
  102.                         }
  103.                     }
  104.                     ShowMsgProgress("Prüfe Dateien für das Update.");
  105.  
  106.                     FileInfo SizecF = new FileInfo(PathClient + "\\" + DirName + "\\" + Fname);
  107.                     FileInfo SizecFz = new FileInfo(PathTo + "\\" + DirName + "\\" + Fname + ".zip");
  108.                     string ZFHash = crc32.Get(PathTo + "\\" + DirName + "\\" + Fname + ".zip").ToString();
  109.  
  110.                     sFU.WriteLine(DirName + "\\" + Fname + "|" + SizecF.Length + "|" + FileHash.ToString() + "|" + SizecFz.Length + "|" + ZFHash);
  111.  
  112.                     if (CL.Contains(DirName + "\\" + Fname))
  113.                     {
  114.                         sCU.WriteLine(DirName + "\\" + Fname + "|" + SizecF.Length + "|" + FileHash.ToString() + "|" + SizecFz.Length + "|" + ZFHash);
  115.                     }
  116.  
  117.  
  118.                     //tick
  119.                     FullFileProgress++;                    
  120.                     UpdateProgressFull(FullFileProgress);
  121.                 }
  122.             }
  123.             ShowMsgProgress("Finalisierung");
  124.  
  125.             if (CriticalExist)
  126.             {
  127.                 sCU.Close();
  128.             }
  129.  
  130.             sFU.Close();
  131.            
  132.  
  133.             if (FulFileExist)
  134.                 File.Delete(PathTo + "\\bin32\\_fll.cy");
  135.  
  136.             ShowMsgProgress("Updateerstellung erfolgreich abgeschlossen.");
  137.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement