Example #1
0
        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");
        }
Example #2
0
        static void UpdateMinimaps(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;
            }

            #region Bilder berechnen
            foreach(string i in files)
            {
                //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;
                        }
                    }
                }

                Console.WriteLine("Überprüfe für Map {0} auf Aktualisierung...", FileSystem.GetFilename(i));

                GC.Collect(2);

                //Hashvergleich
                string text=File.ReadAllText(i);
                string textHash=Hash.SHA1.HashString(text);
                string xmlPath="xml.CalcMinimaps."+FileSystem.GetFilenameWithoutExt(i);

                string xmlHash;
                try
                {
                    xmlHash=Globals.Options.GetElementAsString(xmlPath);
                }
                catch
                {
                    xmlHash="";
                }

                //xmlHash=""; //DEBUG

                if(xmlHash=="")
                {
                    Globals.Options.WriteElement("xml.CalcMinimaps."+FileSystem.GetFilenameWithoutExt(i), textHash);
                }
                else
                {
                    Globals.Options.WriteElement(xmlPath, textHash);
                }

                //Hashvergleich
                if(clearCache==false)
                {
                    if(textHash==xmlHash)
                        continue;
                }

                //Karte berechnen
                Console.WriteLine("Berechne Minimap 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=100;
                pic=pic.Resize(imageSize, (int)(imageSize/imageVerhaeltnis));

                string fn=FileSystem.GetFilenameWithoutExt(i);
                string fnMinimap=Globals.folder_data_graphics_minimaps+fn+".png";
                pic.SaveToFile(fnMinimap);
            }
            #endregion

            Globals.Options.Save();
        }