Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Dec 27, 2016 at 07:38 PM by wesleywh for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by wesleywh · Sep 02, 2015 at 04:09 AM · downloadfilessave-to-filepatchfilepath

Download and Save Binary Files

I'm currently stuck with the patcher for my game. This game isn't big and will be mostly updated for friends. I was wondering if I could get some help. I am getting the following error:

System.ArgumentException: Name has invalid chars at System.IO.FileStream..ctor

I have the diff file on google that it reads and parses through. Then it will download the file from my raw files(also on google drive) and save it to the users local directory. For testing purposes I have made this directory C:\games. I am downloading and saving binary files so they don't have a file extension like .exe or .txt. Here is my Code:

This checks if there is an update needed:

 function checkForUpdates(){    //for the patcher. Check the version first. 
     buildVersion = "1.0.0";
     updating = true;
     showUpdateButton = false;
     updateMsg = "\n\n\n\n\nChecking For Updates..."; //GUI update for user
     yield WaitForSeconds(1.0f);                    //make it visible
     var url = "https://googledrive.com/host/0B9EJGlco2Hy6fkU4QVVzMlQ0QnBqTmVjazZTR2dTSkJJal83eEhlYVJsU1puSjA2b3h3VU0/version.txt"; //txt file with version # in it
     updateMsg = "\n\n\n\n\nEstablishing Connection...";//GUI update for user
     var patchwww:WWW = WWW(url); //create new web connection to the build number site
     yield patchwww;     // wait for download to finish
       
     if (patchwww.text == buildVersion){    //check version
            updateMsg = "\n\n\nCurrently update to date.";
            yield WaitForSeconds(1.0f);
            updating = false;
            showGUI = true;
     }
     else {
         patch = patchwww.text;
            updateMsg = "Update Available.\n\n Current Version: "+buildVersion+"\n Patch Version: "+patchwww.text+"\n\n Would you like to download updates?";
         showUpdateButton = true;
     }
 }


The following two functions go about apply and downloading the update(The actual applying is not implemented yet):

 function applyUpdate(fileListing:String){
     updateMsg = "\n\n\nIdentifying Platform";
     var currPatch = "https://googledrive.com/host/0B9EJGlco2Hy6fkU4QVVzMlQ0QnBqTmVjazZTR2dTSkJJal83eEhlYVJsU1puSjA2b3h3VU0/patch_v"+fileListing+".txt";
     if(Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor){
         updateMsg = "\n\n\n\n\nIdentifying updates for the Mac platform\n\nEstablishing Connection...";
         //savePath += "/../../";    //use this to find the executable
     }
     else if(Application.platform ==  RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor){
         updateMsg = "\n\n\n\n\nIdentifying updates for the Windows platform\n\nEstablishing Connection...";
         rawDataFolder ="https://googledrive.com/host/0B9EJGlco2Hy6fmUxQzN3ZVAtYkczRzA0S29ubjhfVGVBUFpHTm9HRmxOeldraDhhOXBCa1E/";
         rawExc = "https://googledrive.com/host/0B9EJGlco2Hy6fkFNeVZELXZqRTc5M01sT1lOWjNfUC1nRmlpcEJfaTczQW1QMHBoMnV0TjA/The Dark Tower.exe";
         //savePath += "/../";    //use this to find the executable
     }
     
     updateMsg = "\n\n\n\nRetrieving List of Files To Be Patched..."; 
     var patchlist:WWW = WWW(currPatch); 
     yield patchlist;
     var fileList = patchlist.text;
      var fileListArray:String[] = fileList.Split("\n" [0]);
      var fileSaveSuccess = true;
      for (var i = 0; i < fileListArray.Length; i++) 
      {
          updateMsg = "\n\n\nFile "+i+" of "+fileListArray.Length+"\n\nDownloading "+fileListArray[i]; 
         yield downloadFile(fileListArray[i]);
         if(errorOccured == true){
             break;
         }
      }
     if(errorOccured == false){
          updateMsg = "\n\n\n\nFile List Retrieved and Downloaded."; 
      }
 }

This is the function im having problems with:

 function downloadFile(file:String){
     var download:WWW = WWW(rawDataFolder+""+file); //download file from platforms raw folder
     yield download;                                 // wait for download to finish
    // var saveLoc = Application.persistentDataPath;    //Location where the files will go
     var saveLoc = "C:/games";
     try{
         Debug.Log(saveLoc+"/"+file);
         File.WriteAllBytes (saveLoc+"/"+file, download.bytes);     //<----PROBLEM HERE.
     }
     catch(error){
         var errorMsg = "";
         var charCount = 0;
         errorMsg = "";
         for(var i = 0; i < error.ToString().Length; i++){
             charCount += 1;
             if(charCount%15 == 0){
                 errorMsg += error.ToString().Substring(i, i+15);
                 errorMsg += "\n";
             }
             if(charCount >89){
                 errorMsg +="...";
                 break;
             }
         }
         
         updateMsg ="Make sure to run this game as Administrator - Error:\n"+errorMsg;
         errorOccured = true;
         Debug.Log(error);
     }
 }

Any help or direction on this one would be helpful.

EDIT: I just found this link

http://docs.unity3d.com/Manual/binarydata.html

where it talks about saving binary data. However, I don't really understand a whole lot of what is happening in that example script.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wesleywh · Sep 05, 2015 at 04:23 PM 0
Share

Anyone? I could really use some help here.

avatar image Positive7 · Sep 05, 2015 at 06:15 PM 0
Share

what's the file name?

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Positive7 · Sep 05, 2015 at 06:40 PM

Make sure your path and file name doesn't have any special characters like space or & or | etc... Some OS doesn't supports it. I guess that's why you having the error.

Comment
Add comment · Show 21 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wesleywh · Sep 05, 2015 at 06:49 PM 0
Share

I notice here that you are adding a "1" onto the end of the filename? Is that important or is that just an example here? Also do you need to Load the file prior to saving it?

Also there weren't any special characters in the name unless google drive adds them. The output was "C:\games\level0".

avatar image Positive7 · Sep 05, 2015 at 06:53 PM 0
Share

That "1" was only for testing because I put it in the same folder.I think yes. but I will check if $$anonymous$$emorystream or something else works.(I'm just going to eat something quickly)

EDIT: Ok I don't know why but now it works like this (it never did before for me):

 IEnumerator downloadFile(string file){
 
         string saveLoc = "C:/games/";
         string url = "http://localhost/" + file + "1";
         WWW www = new WWW(url);
         yield return www;
         while (!www.isDone) {}
         File.WriteAllBytes(saveLoc + file + "2", www.bytes);
     }
avatar image wesleywh · Sep 05, 2015 at 08:31 PM 0
Share

So I am writing this in Javascript. Can you actually say IEnumator vs just function? I thought IEnumator was for C#. Any I am going to try out the code you provided me a little later to see how it works out and I will let you know. Thanks for all the help so far.

avatar image Positive7 · Sep 05, 2015 at 08:41 PM 0
Share

Sorry I forget to translate it to java :

 function downloadFile(file : String){
 
         var saveLoc = "C:/games/";
         var url = "http://localhost/" + file + "1";
         var www = WWW(url);
         yield www;
         while (!www.isDone) {}
         File.WriteAllBytes(saveLoc + file + "2", www.bytes);
     }
avatar image wesleywh · Sep 05, 2015 at 09:27 PM 0
Share

I copied your code for download file and tried it but modified http://localhost to rawDataFolder and it still have me the invalid characters thing :(

ArgumentException: Name has invalid chars

Show more comments

Follow this Question

Answers Answers and Comments

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

reading and writing files in built project,Files 0 Answers

Download files, not stupid HTML code! 0 Answers

Unity - Syncing/Downloading/overwriting files to a local folder accessed by the game when offline? 0 Answers

How can I download/upload file from/to USB Flash Drive? 0 Answers

Find file in unkown location (Steam) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges