160 lines
5.3 KiB
C#
160 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public static class SaveIdentityUtility
|
|
{
|
|
public const string StableCompanyName = "FloatGamingStudio";
|
|
public const string StableProductName = "Bansonic";
|
|
public const string StableApplicationIdentifier = "com.FloatGamingStudio.Bansonic";
|
|
|
|
private static readonly string[] LegacyProductAliases =
|
|
{
|
|
"Bansonic",
|
|
"ban_total",
|
|
"EaseOut_Main_FreshNew"
|
|
};
|
|
|
|
private static readonly string[] LegacyCompanyAliases =
|
|
{
|
|
"FloatGamingStudio",
|
|
"DefaultCompany"
|
|
};
|
|
|
|
private static readonly string[] LegacyIdentifierAliases =
|
|
{
|
|
"com.DefaultCompany.Bansonic",
|
|
"com.FloatGamingStudio.ban_total",
|
|
"com.DefaultCompany.ban_total",
|
|
"com.FloatGamingStudio.EaseOut_Main_FreshNew",
|
|
"com.DefaultCompany.EaseOut_Main_FreshNew"
|
|
};
|
|
|
|
public static string GetPrimaryApplicationIdentifier()
|
|
{
|
|
return StableApplicationIdentifier;
|
|
}
|
|
|
|
public static string GetCanonicalPersistentRoot()
|
|
{
|
|
if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
|
|
{
|
|
string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
string localLow = Path.GetFullPath(Path.Combine(localAppData, "..", "LocalLow"));
|
|
return Path.Combine(localLow, StableCompanyName, StableProductName);
|
|
}
|
|
|
|
return Application.persistentDataPath;
|
|
}
|
|
|
|
public static IReadOnlyList<string> GetApplicationIdentifierVariants()
|
|
{
|
|
var result = new List<string>();
|
|
AddDistinct(result, StableApplicationIdentifier);
|
|
AddDistinct(result, Application.identifier);
|
|
|
|
string currentCompany = SafeTrim(Application.companyName);
|
|
string currentProduct = SafeTrim(Application.productName);
|
|
if (!string.IsNullOrEmpty(currentCompany) && !string.IsNullOrEmpty(currentProduct))
|
|
{
|
|
AddDistinct(result, $"com.{currentCompany}.{currentProduct}");
|
|
}
|
|
|
|
for (int i = 0; i < LegacyIdentifierAliases.Length; i++)
|
|
{
|
|
AddDistinct(result, LegacyIdentifierAliases[i]);
|
|
}
|
|
|
|
for (int companyIndex = 0; companyIndex < LegacyCompanyAliases.Length; companyIndex++)
|
|
{
|
|
for (int productIndex = 0; productIndex < LegacyProductAliases.Length; productIndex++)
|
|
{
|
|
AddDistinct(result, $"com.{LegacyCompanyAliases[companyIndex]}.{LegacyProductAliases[productIndex]}");
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static IReadOnlyList<string> GetPersistentRootVariants(string extraLegacyPath = null)
|
|
{
|
|
var result = new List<string>();
|
|
|
|
AddDistinct(result, GetCanonicalPersistentRoot());
|
|
AddDistinct(result, Application.persistentDataPath);
|
|
|
|
string extraDirectory = string.IsNullOrEmpty(extraLegacyPath) ? null : Path.GetDirectoryName(extraLegacyPath);
|
|
AddDistinct(result, extraDirectory);
|
|
|
|
if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
|
|
{
|
|
string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
string localLow = Path.GetFullPath(Path.Combine(localAppData, "..", "LocalLow"));
|
|
|
|
string currentCompany = SafeTrim(Application.companyName);
|
|
string currentProduct = SafeTrim(Application.productName);
|
|
if (!string.IsNullOrEmpty(currentCompany) && !string.IsNullOrEmpty(currentProduct))
|
|
{
|
|
AddDistinct(result, Path.Combine(localLow, currentCompany, currentProduct));
|
|
}
|
|
|
|
for (int companyIndex = 0; companyIndex < LegacyCompanyAliases.Length; companyIndex++)
|
|
{
|
|
for (int productIndex = 0; productIndex < LegacyProductAliases.Length; productIndex++)
|
|
{
|
|
AddDistinct(result, Path.Combine(localLow, LegacyCompanyAliases[companyIndex], LegacyProductAliases[productIndex]));
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static IReadOnlyList<string> GetVaultFilePathVariants(string fileName)
|
|
{
|
|
var result = new List<string>();
|
|
if (string.IsNullOrWhiteSpace(fileName))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
IReadOnlyList<string> roots = GetPersistentRootVariants();
|
|
for (int i = 0; i < roots.Count; i++)
|
|
{
|
|
string root = roots[i];
|
|
if (string.IsNullOrWhiteSpace(root))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
AddDistinct(result, Path.Combine(root, ".cache_bridge", fileName));
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private static void AddDistinct(List<string> target, string value)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < target.Count; i++)
|
|
{
|
|
if (string.Equals(target[i], value, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
target.Add(value);
|
|
}
|
|
|
|
private static string SafeTrim(string value)
|
|
{
|
|
return string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
|
}
|
|
}
|