예제 #1
0
        public void Update()
        {
            try
            {
                if (MarkerDownloader != null && MarkerDownloader.Finished)
                {
                    string text = System.Text.UTF8Encoding.UTF8.GetString(MarkerDownloader.Data);
                    LitJson.JsonData node = LitJson.JsonMapper.ToObject(text);
                    for (int i = 0; i < node["markers"].Count; i++)
                    {
                        string n = node["markers"][i]["name"].ToString().Replace("\"", "");
                        if (IngameMap.markerSettings.ContainsKey(n))
                        {
                            Markers.Add(new Marker(node["markers"][i], IngameMap.markerSettings[n]));
                        }
                    }
                    MarkerDownloader = null;
                }
                if (HashDownloader != null && HashDownloader.Finished)
                {
                    string text = System.Text.UTF8Encoding.UTF8.GetString(HashDownloader.Data);
                    serverHash = ConvertHexStringToByteArray(text);
                    bool identical = true;
                    for (int i = 0; i < loadedHash.Length; i++)
                    {
                        if (loadedHash[i] != serverHash[i])
                        {
                            identical = false;
                            this.Downloader.StartDownload();
                            break;
                        }
                    }
                    if (identical)
                    {
                        CurrentTexture = 0;
                    }
                    HashDownloader = null;
                }
                // load textures distributed over frames
                if (CurrentTexture >= 0)
                {
                    LoadTexture();
                }

                if (this.Downloader.Finished && !downloadParsed)
                {
                    string directoryName = System.IO.Path.GetDirectoryName(filename);
                    if (!System.IO.Directory.Exists(directoryName))
                        System.IO.Directory.CreateDirectory(directoryName);
                    System.IO.File.WriteAllBytes(filename, Downloader.Data);
                    ParseTextures();
                    downloadParsed = true;
                }
            } catch (Exception e)
            {
                ModAPI.Log.Write(e.ToString());
            }
        }
예제 #2
0
 public Map(string url, string hashURL, string markerURL, string filename)
 {
     Textures = new Texture2D[SPLIT * SPLIT];
     this.filename = filename;
     this.url = url;
     this.HashDownloader = new Downloader(hashURL, false);
     this.Downloader = new Downloader(url, false);
     this.MarkerDownloader = new Downloader(markerURL, true);
     if (System.IO.File.Exists(filename))
     {
         System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
         loadedHash = md5.ComputeHash(System.IO.File.ReadAllBytes(filename));
         this.HashDownloader.StartDownload();
     }
     else
     {
         this.Downloader.StartDownload();
     }
 }