Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Compile()
- {
- Crc32 crc32 = new Crc32();
- int FullFileProgress = 0;
- bool FulFileExist = false;
- bool CriticalExist = true;
- if (CL.Count <= 0)
- CriticalExist = false;
- if (CriticalExist)
- {
- ShowMsgProgress("Kritische Dateien werden aktualisiert.");
- }
- ShowMsgProgress("Zum Schreiben crt.cy öffnen.");
- FileStream fsCU = new FileStream(PathTo + "\\bin32\\crt.cy", FileMode.Open, FileAccess.Write);
- StreamWriter sCU = new StreamWriter(fsCU);
- ShowMsgProgress("Zum Schreiben fll.cy öffnen.");
- FileStream fsFU = new FileStream(PathTo + "\\bin32\\fll.cy", FileMode.Open, FileAccess.Write);
- StreamWriter sFU = new StreamWriter(fsFU);
- ShowMsgProgress("Suche nach _fll.cy");
- if (File.Exists(PathTo + "\\bin32\\_fll.cy"))
- FulFileExist = true;
- if (FulFileExist)
- {
- ShowMsgProgress("Datei eines älteren Backups gefunden!");
- ShowMsgProgress("Für ein erfolgreiches Update bitte überprüfen.");
- }
- ShowMsgProgress("Erster Schritt");
- DirectoryInfo diFromDir = new DirectoryInfo(@PathClient);
- DirectoryInfo[] diFromArr = diFromDir.GetDirectories();
- foreach (DirectoryInfo DirName in diFromArr)
- {
- DirectoryInfo fFromDir = new DirectoryInfo(@PathClient + "/" + DirName);
- ShowMsgProgress("Lese Verzeichnis: " + DirName);
- foreach (FileInfo Fname in fFromDir.GetFiles())
- {
- //params
- bool ToZip = true;
- UpdateFileProgress(0);
- ShowMsgProgress("Überprüfe Update-Verzeichnis: " + DirName);
- if (!System.IO.Directory.Exists(PathTo + "\\" + DirName))
- {
- ShowMsgProgress("Ordner nicht Vorhanden. Erstelle Ordner: " + DirName);
- System.IO.Directory.CreateDirectory(PathTo + "\\" + DirName);
- }
- ShowMsgProgress("Status: " + Fname);
- string FileHash = crc32.Get(PathClient + "\\" + DirName + "\\" + Fname);
- if (FulFileExist)
- {
- string line;
- StreamReader readLastAllFile = new StreamReader(@PathTo + "\\bin32\\_fll.cy");
- //readLastAllFile.
- while ((line = readLastAllFile.ReadLine()) != null)
- {
- string[] sLine = line.Split(delimeter, StringSplitOptions.RemoveEmptyEntries);
- if (sLine[0].Trim() == DirName+"\\"+Fname)
- {
- if (File.Exists(PathTo + "\\" + sLine[0] + ".zip"))
- {
- ShowMsgProgress("Datei: " + Fname + " wird bereits aktualisiert.");
- ShowMsgProgress("Prüfe Datei: " + Fname + " auf Veränderungen.");
- if (FileHash == sLine[2].Trim() && sLine[4].Trim() == crc32.Get(PathTo + "\\" + sLine[0] + ".zip"))
- {
- ShowMsgProgress("Hash von: " + Fname + " stimmt mit dem Original überein. Überspringe.");
- ToZip = false;
- }
- }
- }
- }
- readLastAllFile.Close();
- }
- if (ToZip)
- {
- ShowMsgProgress("Archivierungsdatei: " + PathClient + "\\" + DirName + "\\" + Fname);
- using (ZipFile zip = new ZipFile()) // Erstelle Archiv
- {
- zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression; // Kompressionsgrad
- zip.AddFile(@PathClient + "\\" + DirName + "\\" + Fname, "");
- zip.Save(@PathTo + "\\" + DirName + "\\" + Fname + ".zip"); // erstelle Sicherungskopie
- }
- }
- ShowMsgProgress("Prüfe Dateien für das Update.");
- FileInfo SizecF = new FileInfo(PathClient + "\\" + DirName + "\\" + Fname);
- FileInfo SizecFz = new FileInfo(PathTo + "\\" + DirName + "\\" + Fname + ".zip");
- string ZFHash = crc32.Get(PathTo + "\\" + DirName + "\\" + Fname + ".zip").ToString();
- sFU.WriteLine(DirName + "\\" + Fname + "|" + SizecF.Length + "|" + FileHash.ToString() + "|" + SizecFz.Length + "|" + ZFHash);
- if (CL.Contains(DirName + "\\" + Fname))
- {
- sCU.WriteLine(DirName + "\\" + Fname + "|" + SizecF.Length + "|" + FileHash.ToString() + "|" + SizecFz.Length + "|" + ZFHash);
- }
- //tick
- FullFileProgress++;
- UpdateProgressFull(FullFileProgress);
- }
- }
- ShowMsgProgress("Finalisierung");
- if (CriticalExist)
- {
- sCU.Close();
- }
- sFU.Close();
- if (FulFileExist)
- File.Delete(PathTo + "\\bin32\\_fll.cy");
- ShowMsgProgress("Updateerstellung erfolgreich abgeschlossen.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement