Search code examples
unity-game-enginesaving-datapatchdownloading-website-files

Unity Patcher. Name has invalid chars Error


I have written a patcher for my game but I am stuck at the actual saving of the files part. I keep on getting the following error from unity:

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

Here is the code that is in charge of saving my files:

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+".FILE", download.bytes);     //<----PROBLEM HERE.
    }
    catch(error){   
        updateMsg ="Update Failed with error message:\n\n"+error.ToString();
        errorOccured = true;
        Debug.Log(error);
    }
}

I am trying to download a file called "level0". It doesn't have a file extension... in windows explorer it says it is simply 'FILE'. So I was thinking it was a binary file. Am I wrong? What might be causing my null character problem? This missing extension? Any help on this would be amazing.


Solution

  • I found out that my problem originated in the text file that I was reading. The text file must have had spaces in it. Using the ".Trim()" command I was able to remove the invalid char error. Once that was removed it worked perfectly reading files without extensions (Binary Files).