chip-gameV3/Assets/Scripts/Common/ExternalFilesGetter.cs
sega 8a6d23b77d Реорг Scripts
Разделено на 4 модуля
- Menu
- Gameplay
- Settings
- Common
2026-07-15 10:49:55 +03:00

58 lines
1.7 KiB
C#

using System;
using System.IO;
using UnityEngine;
public static class ExternalFilesGetter
{
const string SETTINGS_PASSWORD = "SettingsPwd.rr";
public static string GetSettingsPassword()
{
string filePath = Path.Combine(Application.persistentDataPath, SETTINGS_PASSWORD);
try
{
// Проверяем существование файла
if (!File.Exists(filePath))
{
Debug.LogWarning($"Файл {SETTINGS_PASSWORD} не найден по пути: {filePath}");
return null;
}
// Читаем содержимое файла
string password = File.ReadAllText(filePath).Trim();
// Убираем лишние пробелы и проверяем на пустоту
if (string.IsNullOrWhiteSpace(password))
{
Debug.LogWarning($"Файл {SETTINGS_PASSWORD} пуст");
return null;
}
return password;
}
catch (Exception ex)
{
Debug.LogError($"Ошибка при чтении файла {SETTINGS_PASSWORD}: {ex.Message}");
return null;
}
}
public static void SetPassword(string password)
{
string filePath = Path.Combine(Application.persistentDataPath, SETTINGS_PASSWORD);
try
{
File.WriteAllText(filePath, password);
Console.WriteLine($"Файл успешно записан: {filePath}");
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка при записи файла: {ex.Message}");
throw;
}
}
}