Ошибка при чтении файлов
Делаю игру на Unity. При чтении json-файла возникает ошибка FileNotFoundException, а при попытке найти файлы UnauthorizedAccessException. Игра тестировалась на 4 компах, на 3 всё было нормально, всё благополучно читалось-записывалось, но на 4м возникают такие проблемы. Прошу помощи, ума не приложу в чём может быть проблема, неужели нужно програмно выдавать права на директорию для записи и чтения?
Код с чтением файла:
void Awake()
{
if (!PlayerPrefs.HasKey("Language"))
{
if (Application.systemLanguage == SystemLanguage.Russian || Application.systemLanguage == SystemLanguage.Ukrainian || Application.systemLanguage == SystemLanguage.Belarusian)
{
PlayerPrefs.SetString("Language", "ru_RU");
}
else
{
PlayerPrefs.SetString("Language", "en_US");
}
}
currentLanguage = PlayerPrefs.GetString("Language");
LoadLocalizedText(currentLanguage);
}
public void LoadLocalizedText(string langName)
{
//string path = Application.streamingAssetsPath + "/Languages/" + langName + ".json";
string path = Path.Combine(Application.streamingAssetsPath + "/Languages/", langName + ".json");
string dataAsJson;
dataAsJson = File.ReadAllText(path);
LocalizationData loadedData = JsonUtility.FromJson<LocalizationData>(dataAsJson);
localizedText = new Dictionary<string, string>();
for (int i = 0; i < loadedData.items.Length; i++)
{
localizedText.Add(loadedData.items[i].key, loadedData.items[i].value);
}
PlayerPrefs.SetString("Language", langName);
currentLanguage = PlayerPrefs.GetString("Language");
isReady = true;
OnLanguageChanged?.Invoke();
}
Код с поиском файлов:
public void SaveListOutput(GameObject listType)
{
// Удаление старых объектов
for (int i = 0; i < listType.transform.childCount; i++)
{
Destroy(listType.transform.GetChild(i).gameObject);
}
List<string> savesList = (from a in Directory.GetFiles(Application.persistentDataPath, "*.gamesave") select Path.GetFileName(a)).ToList();
for (int i = 0; i < savesList.Count; i++)
{
GameObject saveInFolder = Instantiate(slButton);
saveInFolder.transform.SetParent(listType.transform);
saveInFolder.transform.localScale = new Vector3(1, 1, 1);
saveInFolder.transform.GetChild(0).GetComponent<Text>().text = savesList[i];
saveInFolder.tag = "Save File";
if(saveDeleteToggle.isOn)
{
// Режим удаления сохранений
saveInFolder.GetComponent<Image>().color = Color.red;
saveInFolder.GetComponent<Button>().onClick.AddListener(DeleteSaveConfirmedMenu);
} else
{
// Режим загрузки
saveInFolder.GetComponent<Button>().onClick.AddListener(ExistSaveConfirmed);
}
}
}
Лог с ошибками:
Mono path[0] = 'C:/Program Files (x86)/Steam/steamapps/common/Scraplers/Scraplers_Data/Managed'
Mono config path = 'C:/Program Files (x86)/Steam/steamapps/common/Scraplers/MonoBleedingEdge/etc'
Initialize engine version: 2019.3.14f1 (2b330bf6d2d8)
[Subsystems] Discovering subsystems at path C:/Program Files (x86)/Steam/steamapps/common/Scraplers/Scraplers_Data/UnitySubsystems
GfxDevice: creating device client; threaded=1
Direct3D:
Version: Direct3D 11.0 [level 11.1]
Renderer: AMD Radeon RX 5700 XT (ID=0x731f)
Vendor: (null)
VRAM: 3072 MB
Driver: 27.20.12029.1000
Begin MonoManager ReloadAssembly
- Completed reload, in 1.580 seconds
D3D11 device created for Microsoft Media Foundation video decoding.
<RI> Initializing input.
<RI> Input initialized.
<RI> Initialized touch support.
UnloadTime: 0.943100 ms
Громкость музыки: 1
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)
FileNotFoundException: Could not find file "C:\Program Files (x86)\Steam\steamapps\common\Scraplers\Scraplers_Data\StreamingAssets\Languages\en_US.json"
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0019e] in <437ba245d8404784b9fbab9b439ac908>:0
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.IO.FileOptions options, System.String msgPath, System.Boolean bFromProxy, System.Boolean useLongPath, System.Boolean checkHost) [0x00000] in <437ba245d8404784b9fbab9b439ac908>:0
at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,System.IO.FileOptions,string,bool,bool,bool)
at System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize, System.Boolean checkHost) [0x00067] in <437ba245d8404784b9fbab9b439ac908>:0
at System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize) [0x00000] in <437ba245d8404784b9fbab9b439ac908>:0
at System.IO.StreamReader..ctor (System.String path, System.Boolean detectEncodingFromByteOrderMarks) [0x0000d] in <437ba245d8404784b9fbab9b439ac908>:0
at System.IO.StreamReader..ctor (System.String path) [0x00000] in <437ba245d8404784b9fbab9b439ac908>:0
at (wrapper remoting-invoke-with-check) System.IO.StreamReader..ctor(string)
at System.IO.File.ReadAllText (System.String path) [0x00000] in <437ba245d8404784b9fbab9b439ac908>:0
at LocalizationManager.LoadLocalizedText (System.String langName) [0x00015] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at LocalizationManager.Awake () [0x00056] in <9db3ab8d44e44bf4ab3a0123215616af>:0
(Filename: <437ba245d8404784b9fbab9b439ac908> Line: 0)
NullReferenceException: Object reference not set to an instance of an object
at LocalizationManager.GetLocalizedValue (System.String key) [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at MainMenuScript.Start () [0x00033] in <9db3ab8d44e44bf4ab3a0123215616af>:0
(Filename: <9db3ab8d44e44bf4ab3a0123215616af> Line: 0)
NullReferenceException: Object reference not set to an instance of an object
at LocalizationManager.GetLocalizedValue (System.String key) [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at LocalizedText.UpdateText () [0x0004c] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at LocalizedText.Start () [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
(Filename: <9db3ab8d44e44bf4ab3a0123215616af> Line: 0)
NullReferenceException: Object reference not set to an instance of an object
at LocalizationManager.GetLocalizedValue (System.String key) [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at LocalizedText.UpdateText () [0x0004c] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at LocalizedText.Start () [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
(Filename: <9db3ab8d44e44bf4ab3a0123215616af> Line: 0)
NullReferenceException: Object reference not set to an instance of an object
at LocalizationManager.GetLocalizedValue (System.String key) [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at LocalizedText.UpdateText () [0x0004c] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at LocalizedText.Start () [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
(Filename: <9db3ab8d44e44bf4ab3a0123215616af> Line: 0)
NullReferenceException: Object reference not set to an instance of an object
at LocalizationManager.GetLocalizedValue (System.String key) [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at LocalizedText.UpdateText () [0x0004c] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at LocalizedText.Start () [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
(Filename: <9db3ab8d44e44bf4ab3a0123215616af> Line: 0)
NullReferenceException: Object reference not set to an instance of an object
at LocalizationManager.GetLocalizedValue (System.String key) [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at LocalizedText.UpdateText () [0x0004c] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at LocalizedText.Start () [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
(Filename: <9db3ab8d44e44bf4ab3a0123215616af> Line: 0)
Длинна трека: 301.3747
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)
UnauthorizedAccessException: Access to the path 'C:\Users\mikhail\AppData\LocalLow\Cryoshark\Scraplers' is denied.
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x000e0] in <437ba245d8404784b9fbab9b439ac908>:0
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode) [0x00000] in <437ba245d8404784b9fbab9b439ac908>:0
at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode)
at MainMenuScript.SaveGame (PlayerScript plScr, System.String fileName) [0x00012] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at MainMenuScript.BackToStartMenu () [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at UnityEngine.Events.InvokableCall.Invoke () [0x00010] in <4395812e1db34cd2a0572bd0ec23b7fa>:0
at UnityEngine.Events.UnityEvent.Invoke () [0x00022] in <4395812e1db34cd2a0572bd0ec23b7fa>:0
at UnityEngine.UI.Button.Press () [0x0001c] in <63cbdb71eb544d6e9ce7f360738a268e>:0
at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00009] in <63cbdb71eb544d6e9ce7f360738a268e>:0
at UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00007] in <63cbdb71eb544d6e9ce7f360738a268e>:0
at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) [0x00063] in <63cbdb71eb544d6e9ce7f360738a268e>:0
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.StandaloneInputModule:ReleaseMouse(PointerEventData, GameObject)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMousePress(MouseButtonEventData)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent(Int32)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent()
UnityEngine.EventSystems.StandaloneInputModule:Process()
UnityEngine.EventSystems.EventSystem:Update()
(Filename: <437ba245d8404784b9fbab9b439ac908> Line: 0)
UnauthorizedAccessException: Access to the path 'C:\Users\mikhail\AppData\LocalLow\Cryoshark\Scraplers' is denied.
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x000e0] in <437ba245d8404784b9fbab9b439ac908>:0
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode) [0x00000] in <437ba245d8404784b9fbab9b439ac908>:0
at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode)
at MainMenuScript.SaveGame (PlayerScript plScr, System.String fileName) [0x00012] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at MainMenuScript.BackToStartMenu () [0x00000] in <9db3ab8d44e44bf4ab3a0123215616af>:0
at UnityEngine.Events.InvokableCall.Invoke () [0x00010] in <4395812e1db34cd2a0572bd0ec23b7fa>:0
at UnityEngine.Events.UnityEvent.Invoke () [0x00022] in <4395812e1db34cd2a0572bd0ec23b7fa>:0
at UnityEngine.UI.Button.Press () [0x0001c] in <63cbdb71eb544d6e9ce7f360738a268e>:0
at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00009] in <63cbdb71eb544d6e9ce7f360738a268e>:0
at UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00007] in <63cbdb71eb544d6e9ce7f360738a268e>:0
at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) [0x00063] in <63cbdb71eb544d6e9ce7f360738a268e>:0
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.StandaloneInputModule:ReleaseMouse(PointerEventData, GameObject)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMousePress(MouseButtonEventData)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent(Int32)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent()
UnityEngine.EventSystems.StandaloneInputModule:Process()
UnityEngine.EventSystems.EventSystem:Update()
(Filename: <437ba245d8404784b9fbab9b439ac908> Line: 0)
Setting up 6 worker threads for Enlighten.
Thread -> id: 1384 -> priority: 1
Thread -> id: 137c -> priority: 1
Thread -> id: 2468 -> priority: 1
Thread -> id: 2c78 -> priority: 1
Thread -> id: 158c -> priority: 1
Thread -> id: 3228 -> priority: 1