I'm working on Hololens 2 application in Unity 3D. I'm trying to write a configuration file to the device and access it later via the device portal in a web browser. Within the application itself, I'm being told that the file is being written to AppData/Local/Packages/[App Name]/LocalState/[File Name].txt. However, when I go and take a look at LocalAppData/[App Name] the folder LocalState/ doesn't even exist. I suspect this has to do with an error in the Package.appxmanifest file of the VS project generated by Unity.
Here is the relevant C# code I'm using to write to file:
void ReadResolution()
{
string path = Path.Combine(Application.persistentDataPath, mResFilename);
mExcept = $"No exceptions thrown by file IO while writing to \n\"{path}\".";
if(System.IO.File.Exists(path) && new FileInfo(path).Length > 0)
{
try
{
StreamReader reader = new StreamReader(path);
if(reader != null)
{
string content = reader.ReadToEnd();
string[] split = content.Split(' ');
mWidth = Int32.Parse(split[0]);
mHeight = Int32.Parse(split[1]);
}
}
catch (Exception e)
{
mExcept = "File Read Exception: " + e.Message;
}
}
else
{
try
{
using (TextWriter writer = File.CreateText(path))
{
string line = mWidth.ToString() + " " + mHeight.ToString();
writer.WriteLine(line);
}
}
catch (Exception e)
{
mExcept = "File Write Exception: " + e.Message;
}
}
Debug.Log(mExcept);
}
I'm using the member field mExcept to record any messages or exceptions thrown during the process. It's telling me the file is written successfully, but maybe I'm just fooling myself somehow?
Here are the relevant sections from the project's Package.appxmanifest file:
<Package xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:uap2="http://schemas.microsoft.com/appx/manifest/uap/windows10/2"
xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4"
xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10"
xmlns:mobile="http://schemas.microsoft.com/appx/manifest/mobile/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap uap2 uap3 uap4 mp mobile iot rescap"
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10">
.
.
.
<Capabilities>
<rescap:Capability Name="broadFileSystemAccess" />
<uap:Capability Name="documentsLibrary" />
<Capability Name="internetClient" />
<Capability Name="internetClientServer" />
<Capability Name="privateNetworkClientServer" />
<uap2:Capability Name="spatialPerception" />
<uap3:Capability Name="remoteSystem" />
<DeviceCapability Name="microphone" />
<DeviceCapability Name="gazeinput" />
<DeviceCapability Name="wiFiControl" />
<DeviceCapability Name="webcam" />
</Capabilities>
Any help is appreciated. Thanks in advance.