static void UpdateWorldmap(bool all, bool clearCache) { List<string> files=FileSystem.GetFiles(Globals.folder_data_maps, true, "*.tmx"); if(files==null) { Console.WriteLine("Es wurden keine Maps gefunden."); Console.WriteLine("Eventuell ist der Pfad des Repositories in der Konfigurationdatei falsch."); return; } string temp=FileSystem.TempPath+"Invertika Editor"+FileSystem.PathDelimiter; string tempFmMonsterSpreading=FileSystem.TempPath+"Invertika Editor"+FileSystem.PathDelimiter+"fm-monster-spreading"+FileSystem.PathDelimiter; string tempFmMusic=FileSystem.TempPath+"Invertika Editor"+FileSystem.PathDelimiter+"fm-music"+FileSystem.PathDelimiter; #region Bilderordner löschen und neu anlegen Console.WriteLine("Bereinige Bilderordner..."); FileSystem.RemoveDirectory(temp, true); FileSystem.CreateDirectory(temp, true); FileSystem.CreateDirectory(tempFmMonsterSpreading, true); FileSystem.CreateDirectory(tempFmMusic, true); #endregion #region Bilder berechnen //int debug=0; foreach(string i in files) { Console.WriteLine("Überprüfe für Map {0} auf Aktualisierung...", FileSystem.GetFilename(i)); GC.Collect(2); //Nur sichtbare Weltkarte rendern. if(!all) { Map map=new Map(0, FileSystem.GetFilenameWithoutExt(i)); //if(map.MapType=="iw") continue; //if(map.MapType=="uw") continue; if(map.MapType=="ow") { if(map.X>=-7&&map.X<=7&&map.Y>=-7&&map.Y<=7) { //nichts tun (sprich rendern) } else { continue; } } } //Hashvergleich string text=File.ReadAllText(i); string textHash=Hash.SHA1.HashString(text); string xmlPath="xml.CalcMapImages."+FileSystem.GetFilenameWithoutExt(i); string xmlHash; try { xmlHash=Globals.Options.GetElementAsString(xmlPath); } catch { xmlHash=""; } //xmlHash=""; //DEBUG if(xmlHash=="") { Globals.Options.WriteElement("xml.CalcMapImages."+FileSystem.GetFilenameWithoutExt(i), textHash); } else { Globals.Options.WriteElement(xmlPath, textHash); } if(clearCache==false) { if(textHash==xmlHash) continue; } //Karte berechnen Console.WriteLine("Berechne Bilder für Map {0}", FileSystem.GetFilename(i)); TMX file=new TMX(i); Graphic pic=file.Render(); int imageSizeOriginalWidth=(int)pic.Width; int imageSizeOriginalHeight=(int)pic.Height; double imageVerhaeltnis=imageSizeOriginalWidth/(double)imageSizeOriginalHeight; //int imageSize=6400; int imageSize=800; pic=pic.Resize(imageSize, (int)(imageSize/imageVerhaeltnis)); bool next=true; while(next) { string fn=FileSystem.GetFilenameWithoutExt(i); string fnNumeric=temp+fn+"-"+imageSize+".png"; pic.SaveToFile(fnNumeric); //Featuremap Monster Spreading string fnMonsterSpreading=tempFmMonsterSpreading+fn+"-"+imageSize+".png"; Imaging.SaveFeatureMapMonsterSpreading(Globals.folder_data, fnMonsterSpreading, pic, file); //Featuremap Music string fnMusic=tempFmMusic+fn+"-"+imageSize+".png"; SaveFeatureMapMusic(fnMusic, pic, file); switch(imageSize) { //case 6400: // { // imageSize=1600; // break; // } //case 100: // { // //Minimap zusätzlich speichern // string fnMinimap=Globals.folder_clientdata_graphics_minimaps+fn+".png"; // pic.SaveToFile(fnMinimap); // break; // } case 10: { next=false; break; } } imageSize=GetNextImageSize(imageSize); pic=pic.Resize(imageSize, (int)(imageSize/imageVerhaeltnis)); GC.Collect(3); } //Debug //debug++; //if(debug>5) break; } #endregion #region Bilder per FTP hochladen List<string> filesToUpload=new List<string>(); filesToUpload.AddRange(FileSystem.GetFiles(temp, true, "*.png")); Console.WriteLine("Lade {0} Dateien hoch...", filesToUpload.Count); FTPSClient Client=new FTPSClient(); NetworkCredential networkCredential=new NetworkCredential(); networkCredential.Domain=Globals.Options.GetElementAsString("xml.Options.FTP.Worldmap.Server"); networkCredential.UserName=Globals.Options.GetElementAsString("xml.Options.FTP.Worldmap.User"); networkCredential.Password=Globals.Options.GetElementAsString("xml.Options.FTP.Worldmap.Password"); try { Client.Connect(networkCredential.Domain, networkCredential, ESSLSupportMode.ClearText); } catch(Exception exception) { Console.WriteLine("Fehler: {0}", exception.Message); return; } //Ordner für die Feature Maps if(!Client.Exists("fm-monster-spreading/ow-o0000-o0000-o0000-800.png")) //Monster Spreading { Client.CreateDirectory("fm-monster-spreading"); } if(!Client.Exists("fm-music/ow-o0000-o0000-o0000-800.png")) //Music { Client.CreateDirectory("fm-music"); } for(int i=0;i<filesToUpload.Count;i++) { string filename=filesToUpload[i]; try { Console.WriteLine("Lade Bild {0} hoch...", FileSystem.GetFilename(filename)); string uploadf=FileSystem.GetRelativePath(filename, temp); uploadf=uploadf.Replace('\\', '/'); //Client.UploadFile(i, uploadf); Client.PutFile(filename, uploadf); } catch { Console.WriteLine("Fehler beim Upload von Bild {0}.", FileSystem.GetFilename(filename)); Thread.Sleep(2000); Console.WriteLine("Stelle Verbindung wieder her...", FileSystem.GetFilename(filename)); Client.Connect(networkCredential.Domain, networkCredential, ESSLSupportMode.ClearText); i--; } } Client.Close(); #endregion Globals.Options.Save(); Console.WriteLine("Weltkarte geupdatet"); }
public string GetHistoryHash(FTPSClient client, string relFilename) { string fileNameFTP=relFilename.Replace("/", "\\"); fileNameFTP="h-data/"+fileNameFTP; if(client.Exists(fileNameFTP)) //Neuen Hash hinzufügen { string hashFilenameLocal=FileSystem.TempPath+FileSystem.GetFilename(fileNameFTP); client.GetFile(fileNameFTP, hashFilenameLocal); List<string> hashInfo=new List<string>(); hashInfo.AddRange(File.ReadAllLines(hashFilenameLocal)); return hashInfo[0]; } else //keine Hashdatei vorhanden { return ""; } }
public void CreateFTPDirectories(FTPSClient client, string filename) { string path=FileSystem.GetPath(filename, true, false); string[] parts=path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); string newPath=""; foreach(string part in parts) { newPath+=part; //client.GetDirectoryList if(client.Exists(newPath)==false) { client.EnsureDirectory(newPath); } newPath+="/"; } }
/// <summary> /// Holt einen Dateilock /// </summary> /// <param name="client"></param> /// <param name="file"></param> /// <returns></returns> public bool GetFileLock(FTPSClient client, string file) { file=file.Replace("/", "\\"); file="l-data/"+file; if(client.Exists(file)) //Auf Lock überprüfen { Thread.Sleep(500); if(client.Exists(file)) //Nochmal Auf Lock überprüfen { return false; //Lock konnte nicht geholt werden } } //Lock erzeugen string lockFilenameLocal=FileSystem.TempPath+FileSystem.GetFilename(file); string lockFilenameLocalCheck=FileSystem.TempPath+FileSystem.GetFilename(file)+".check"; List<string> lines=new List<string>(); lines.Add(Globals.ClientID); File.WriteAllLines(lockFilenameLocal, lines.ToArray()); client.PutFile(lockFilenameLocal, file); //Lock überprüfen client.GetFile(file, lockFilenameLocalCheck); string[] linesLockFile=File.ReadAllLines(lockFilenameLocalCheck); string lockID=linesLockFile[0]; if(Globals.ClientID==lockID) //Überprüfen ob das Lock ein Client Lock ist { return true; } else //Kein Client eigenes Lock { return false; } }
/// <summary> /// Holt einen Dateilock /// </summary> /// <param name="client"></param> /// <param name="file"></param> /// <returns>true = New hash / </returns> public bool AddHistoryHash(FTPSClient client, string file, string relFilename) { string fileNameFTP=relFilename.Replace("/", "\\"); fileNameFTP="h-data/"+fileNameFTP; string fileHash=Hash.SHA1.HashFile(file); if(client.Exists(fileNameFTP)) //Neuen Hash hinzufügen { string hashFilenameLocal=FileSystem.TempPath+FileSystem.GetFilename(fileNameFTP); client.GetFile(fileNameFTP, hashFilenameLocal); List<string> hashInfo=new List<string>(); hashInfo.AddRange(File.ReadAllLines(hashFilenameLocal)); if(hashInfo[0]==fileHash) { return false; } else { hashInfo.Add(fileHash); File.WriteAllLines(hashFilenameLocal, hashInfo.ToArray()); client.PutFile(hashFilenameLocal, fileNameFTP); return true; } } else //Hash Datei erzeugen { List<string> hashFile=new List<string>(); hashFile.Add(fileHash); //Repository Version string hashFilenameLocal=FileSystem.TempPath+"hash-"+Various.GetTimeID(); File.WriteAllLines(hashFilenameLocal, hashFile.ToArray()); client.PutFile(hashFilenameLocal, fileNameFTP); return true; } }