static void GetGameUpdateZIP()
    {
        double fProgress = 0.0f;

        double startVal  = EditorApplication.timeSinceStartup;
        WWW    XMLUpdate = new WWW("http://app.doodletales.co.uk/www/include/getxmlparsed_zip_wfs2.php");

        double fLastProgress = fProgress;

        while (XMLUpdate.isDone == false)
        {
            fProgress = (EditorApplication.timeSinceStartup - startVal) * 30.0f;
            //UnityEngine.Debug.Log( fProgress % 1.0f );

            if ((fProgress - fLastProgress) > 0.1f)
            {
                fLastProgress = fProgress;

                EditorUtility.DisplayProgressBar(
                    "Get Game Update ZIP",
                    "Downloading... (can be slow!!)",
                    (float)fProgress % 17.0f);
            }
        }
        ;
        EditorUtility.ClearProgressBar();

        if (String.IsNullOrEmpty(XMLUpdate.error))
        {
            UnityEngine.Debug.Log("Updated WFS2.zip OK");

            // Find checksum of file (simple, just for checking validity later)
            uint Checksum = HelperChecksum.GetChecksum(XMLUpdate.bytes);

            string savePath = EditorUtility.SaveFilePanel(
                "Save game ZIP",
                "",
                "wfs2_" + Checksum.ToString("X") + ".zip",
                "zip");

            if (savePath.Length != 0)
            {
                // Save file
                File.WriteAllBytes(savePath, XMLUpdate.bytes);
            }
        }
        else
        {
            UnityEngine.Debug.Log("ZIP Downloaded with error: " + XMLUpdate.error);
        }
    }
    static void UpdateZIPChecksum()
    {
        // Open zip file
        string loadPath = EditorUtility.OpenFilePanel(
            "Load game ZIP",
            "",
            "zip");

        if (loadPath.Length != 0)
        {
            // Load zip
            if (System.IO.File.Exists(loadPath))
            {
                FileStream   fs = new FileStream(loadPath, FileMode.Open);
                BinaryReader r  = new BinaryReader(fs);

                int ZIPSize = (int)fs.Length;

                byte[] SourceDataPtr;

                SourceDataPtr = r.ReadBytes(ZIPSize);
                uint Checksum = HelperChecksum.GetChecksum(SourceDataPtr);

                EditorUtility.DisplayDialog("ZIP Checksum", "New ZIP file checksum is wfs2_" + Checksum.ToString("X") + ".zip", "OK", "Cancel");
                //UnityEngine.Debug.Log( Checksum.ToString("X") );

                string savePath = EditorUtility.SaveFilePanel(
                    "Save updated game ZIP",
                    "",
                    "wfs2_" + Checksum.ToString("X") + ".zip",
                    "zip");

                if (savePath.Length != 0)
                {
                    // Save file
                    File.WriteAllBytes(savePath, SourceDataPtr);
                }

                r.Close();
                fs.Close();
            }
        }
    }
示例#3
0
    //=============================================================================

    IEnumerator GetLiveData(int Version, string URL)
    {
        WWW GameDataWWW = new WWW(URL);

        yield return(GameDataWWW);

        uint NewGameDataChecksum = 0;

        // Find checksum
        int ChecksumIndex = URL.IndexOf("wfs2_");

        if (ChecksumIndex != -1)
        {
            try
            {
                NewGameDataChecksum = uint.Parse(URL.Substring(ChecksumIndex + 5, 8), System.Globalization.NumberStyles.HexNumber);
            }
            catch
            {
                NewGameDataChecksum = 0;
            }
        }

        if (String.IsNullOrEmpty(GameDataWWW.error) && (GameDataWWW.bytes != null))
        {
            UnityEngine.Debug.Log("Updated Game Data OK");

            // Make sure checksum matches
            uint Checksum = HelperChecksum.GetChecksum(GameDataWWW.bytes);
            if (Checksum == NewGameDataChecksum)
            {
                // Save file
                string DocPath  = PreHelpers.GetFileFolderPath();
                string FilePath = DocPath + "wfs2.zip";

                // Write file
                FileStream fs = null;
                try
                {
                    fs = new FileStream(FilePath, FileMode.Create);
                }
                catch
                {
                    Debug.Log("GameData file creation exception: " + FilePath);
                }

                if (fs != null)
                {
                    PlayerPrefs.SetInt("LiveDataVersion", Version);

                    BinaryWriter CurFile = new BinaryWriter(fs);
                    CurFile.Write(GameDataWWW.bytes);

                    // Close file
                    CurFile.Close();
                    fs.Close();

                    // Unzip into local data files
                    //PreHelpers.LoadGameDataUpdate();
                }
            }
            else
            {
                UnityEngine.Debug.Log("Game Data update checksum mismatch: " + Checksum.ToString("X") + " " + NewGameDataChecksum.ToString("X"));
            }
        }
        else
        {
            UnityEngine.Debug.Log("Game Data updated error: " + GameDataWWW.error);
        }
    }