The third day of imitation LOL project development

Source: Internet
Author: User

The second day of imitation LOL project development

by Straw Hat

Yesterday we have implemented the download function, but found that no, download the package is compressed, no decompression open, then unity is not recognized.

So today we're talking about how to implement an extract file.

Remember, we added a downloadtask inside the download after the completion of an extract delegate, we have not implemented, then we go to solve him.

Back to VersionManager's Downloadpackagelist method, add the extracted code to the ondownloadfinished delegate.

I have previously talked about a single function of the class, so it is impossible to complete the decompression function in VersionManager.

So, we create a new file management class: FileAccessManager.cs:

Using unityengine;using system.collections;using system.io;using system.linq;using System.Text.RegularExpressions; Using icsharpcode.sharpziplib.zip;///<summary>///File Manager//</summary>public Static class Fileaccessmanager {//<summary>///Extract files to the resource file directory///</summary>//<param name= "FilePath" > </param> public static void Decompressfile (String filePath) {decompresstodirectory (systemconfig.resour    Cefolder, FilePath);    }///<summary>//Unzip the file to the specified file path///</summary>//<param name= "TargetPath" ></param> <param name= "Zipfilepath" ></param> public static void Decompresstodirectory (String targetpath,string             Zipfilepath) {if (file.exists (Zipfilepath)) {Stream compressed = File.openread (Zipfilepath); Compressed.        Decompresstodirectory (TargetPath);        } else {debug.logerror ("uncompressed file does not exist"); }} Private static void Decompresstodirectory (this Stream source, string targetpath) {TargetPath = Path.GetFullPath (targe        Tpath);            using (Zipinputstream decompressor = new Zipinputstream (source)) {ZipEntry entry; while (entry = decompressor. Getnextentry ()) = null) {string name = entry.                Name; if (entry. Isdirectory && entry. Name.startswith ("\ \")) name = entry.                    Name.replacefirst ("\ \", ""); Name = Replacefirst (entry.                Name, "\ \", "" ");                String filePath = Path.Combine (TargetPath, name);                String directorypath = Path.getdirectoryname (FilePath); if (!string. IsNullOrEmpty (directorypath) &&!                Directory.Exists (DirectoryPath)) directory.createdirectory (DirectoryPath); if (entry.                Isdirectory) continue;                byte[] data = new byte[2048]; using (FilestreaM streamWriter = file.create (FilePath)) {int bytesread; while (bytesread = decompressor. Read (data, 0, data.                    Length)) > 0) {streamwriter.write (data, 0, bytesread); }}}}} public static string Replacefirst (the This string source, string oldstring, S        Tring newstring) {regex regex = new Regex (oldstring, regexoptions.multiline); return Regex.Replace (source, newstring = = null?)      "": newstring, 1); }}

Do not understand the unzip the file of children's shoes can read my other blog: General Tools Extract Files 

Here I will not elaborate, we continue to return to VersionManager's downloadpackagelist:

Action ondownloadfinished = () =            {                //unzip, later                if (file.exists (localfile))                {                    //start extracting files                    Fileaccessmanager.decompressfile (LocalFile);                }                if (file.exists (localfile))                {                    file.delete (localfile);                }                Update local version information                localversion.resourceversioncodeinfo = new Versioncodeinfo (kvp. Key);                Save version Information                saveversion (localversion);            };

Saveversion (): Update local version information XML

    <summary>///    save version information to an XML file///</summary>//    <param name= "version" ></param >    private void Saveversion (Versionmanagerinfo version)    {        var props = typeof (Versionmanagerinfo). GetProperties ();        XmlDocument doc = new XmlDocument ();        XmlDeclaration newChild = doc. Createxmldeclaration ("1.0", "UTF-8", null);        Doc. AppendChild (newChild);        XmlElement root = Doc. createelement ("root");        Doc. AppendChild (root);        foreach (Var prop in props)        {            XmlElement e = doc. CreateElement (Prop. Name);            String value = Prop. Getgetmethod (). Invoke (Version,null) as String;            E.innertext = value;            Root. AppendChild (e);        }        Unitytools.savetext (Systemconfig.versionpath, Doc. INNERXML);    }

Ok, let's run the program, eh, found the error, and the same error.

That is to say get application.datapath cannot be fetched on other threads, we look at those who get the thread.

Found, that is, at the time of DOWNLOADMRG's checkdownloadlist. New A download thread:

So the solution is still, go to the Downloadtask class inside, find the Onfinished method, modify the following:

    public void onfinished ()    {        if (finished! = null)            Lolgamedriver.invoke (finished);            Finished ();    }

Then go back to DOWNLOADFINISHEDWITHMD5 () and find the task. Finished () changed to task. Onfinished ();

Run the program again:

You can see that the original compressed files have been automatically unpacked (see the children's shoes please refresh the resources under Project), because we have modified the version information, so run again to see:

You can see that the update is not needed and that the version has been iterated. Ok, basically the version update has made a paragraph, now only the difference and interface interaction, so the next section, we specifically talk about the interface UI framework.

The third day of imitation LOL project development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.