Problem with reading from StreamingAssets Unity

Viewed 528

If the user installs the program to the C:\Program Files (x86) directory, then when reading from StreamingAssets, an exception appears UnauthorizedAccessException: Access to the path "C:\Program Files (x86) ... is denied" The user does not have administrator rights. Running as administrator doesn't help. I have no control over where the user installs the program. This is how I read the file

string pathToDefaultScene = $"{Application.streamingAssetsPath}/DefaultScene.crscene";
using (var stream = new FileStream(pathToDefaultScene , FileMode.Open))
{
    stream.Read(sceneLengthBytes, 0, sizeof(int));
    stream.Read(imageLengthBytes, 0, sizeof(int));
    stream.Read(metadataLengthBytes, 0, sizeof(int));
    var sceneLength = BitConverter.ToInt32(sceneLengthBytes, 0);
    imageLength = BitConverter.ToInt32(imageLengthBytes, 0);
    var metadataLength = BitConverter.ToInt32(metadataLengthBytes, 0);
    sceneBytes = new byte[sceneLength];
    imageBytes = new byte[imageLength];
    metadataBytes = new byte[metadataLength];
    stream.Read(sceneBytes, 0, sceneLength);
    stream.Read(imageBytes, 0, imageLength);
    stream.Read(metadataBytes, 0, metadataLength);
}
1 Answers
Related