Skip to content
Snippets Groups Projects
Commit a32f86b8 authored by Stefan Richter's avatar Stefan Richter
Browse files

Implemented Get_DataPath() with internal Handler

parent 597ba19b
No related branches found
No related tags found
No related merge requests found
......@@ -77,6 +77,8 @@ public enum OperationSystem
{
Windows = 0,
Android = 1,
iOS =2,
WindowsStoreApps = 3,
}
public static bool CursorVisDefault = true; //Script.
......@@ -106,6 +108,21 @@ public static string CreateHierarchiePath(List<Directories> hierarchie, string p
return System.IO.Path.Combine(prefix, postfix);
}
public static string Get_DataPath()
{
string Target_StreamToDataPath_writeable = Path.Combine(Application.persistentDataPath, "DataPath_writeable");
string dataPath = Opsys switch
{
OperationSystem.Android => Target_StreamToDataPath_writeable,
OperationSystem.Windows or _ => Application.dataPath,
};
if(Application.isEditor) { dataPath = Target_StreamToDataPath_writeable; }
return dataPath;
}
// TODO! avoid tree traversel with name
public static string CreatePathToFile(out bool file_exists, string name, string format = null, List<Directories> hierarchie = null, bool use_install_folder = false)
{
......@@ -120,14 +137,11 @@ public static string CreatePathToFile(out bool file_exists, string name, string
break;
}
string path = Opsys switch
string path = Application.persistentDataPath;
if (use_install_folder)
{
OperationSystem.Android => Application.persistentDataPath,
OperationSystem.Windows or _ => use_install_folder ? Application.dataPath : Application.persistentDataPath,
};
string Target_StreamToDataPath_UnityEditor = "UnityEditor";
if (Application.isEditor && use_install_folder) { path = Path.Combine(Application.persistentDataPath, Target_StreamToDataPath_UnityEditor); }
path=Get_DataPath();
}
if (hierarchie != null)
{
......
......@@ -16,7 +16,7 @@ public static class StreamingAssetLoader
public static string StreamToPersistentDataPath_Folder_Cookie = "cookie_persistentDataPath.txt";
public static string StreamToDataPath_withHandler_Folder = "StreamToDataPath_withHandler";
public static string PersDataPathToPlayerSaveGame_Path = "stages/SaveGames";
public static string Target_StreamToDataPath_UnityEditor = "UnityEditor";
public static string Target_StreamToDataPath_UnityEditor = "DataPath_writeable";
//Config
......@@ -38,6 +38,7 @@ public static void ResetPlayerConfig()
NetworkJSON_Load();
}
public static bool ReloadManualy_StreamToPers()
{
ResetPlayerConfig();
......@@ -52,7 +53,7 @@ public static bool ReloadManualy_StreamToPers()
public static bool ReloadManualy_StreamToDataPath()
{
string sourcePath = Path.Combine(Application.streamingAssetsPath, StreamToDataPath_Folder);
string targetFolder = Application.dataPath;
string targetFolder = Get_DataPath();
RereadFileWithUnityWebRequest(sourcePath, "", StreamToDataPath_Folder_Cookie, targetFolder);
NetworkJSON_Load();
......@@ -61,7 +62,6 @@ public static bool ReloadManualy_StreamToDataPath()
}
public static bool ReloadManualy_StreamToDataPathWithHandler(string TargetDir_1)
{
string sourcePath = Path.Combine(Application.streamingAssetsPath, StreamToDataPath_withHandler_Folder);
string targetFolder_dpwh = TargetDir_1;
//Debug.Log(targetFolder_dpwh);
......@@ -94,7 +94,7 @@ public static bool checkPersistentDataPath()
}
public static bool checkDataPath()
{
return checkFileExistence(Application.dataPath, StreamToDataPath_Folder_Cookie);
return checkFileExistence(Get_DataPath(), StreamToDataPath_Folder_Cookie);
}
public static bool checkFileExistence(string sourcepath, string filename)
{
......@@ -231,10 +231,10 @@ public static void RereadFiles_DataPath()
{
//Debug.Log("Reread_DataPath");
string rootPath = Path.Combine(Application.streamingAssetsPath, StreamToDataPath_Folder);
string targetFolder = Application.dataPath;
string targetFolder = Application.dataPath;
if (Application.isEditor)
{
targetFolder = Path.Combine(Application.persistentDataPath, Target_StreamToDataPath_UnityEditor);
Get_DataPath();
}
RereadFiles_DataPath_withHandler();
......@@ -248,22 +248,10 @@ public static void RereadFiles_DataPath()
public static void RereadFiles_DataPath_withHandler()
{
string rootPath = Path.Combine(Application.streamingAssetsPath, StreamToDataPath_withHandler_Folder);
string targetFolder_wh = Application.dataPath;
//Debug.Log(CommunicationEvents.Opsys);
if (CommunicationEvents.Opsys == OperationSystem.Android)
{
targetFolder_wh = Application.persistentDataPath;
//Debug.Log(OperationSystem.Android + " " + targetFolder_wh);
}
if (Application.isEditor)
{
targetFolder_wh = Path.Combine(Application.persistentDataPath, Target_StreamToDataPath_UnityEditor);
}
string targetFolder_wh = Get_DataPath();
if (!ReReadFiles(rootPath, targetFolder_wh))
{
//Debug.Log( " 2 " + targetFolder_wh);
{
ReloadManualy_StreamToDataPathWithHandler(targetFolder_wh);
}
}
......@@ -518,7 +506,7 @@ public static void RereadFileUWR(string pathfolders, string fileName, ID_toPath
{
//copies and unpacks file from apk to persistentDataPath where it can be accessed
string destinationPath;
if (toMainpath == ID_toPath.DataPath && CommunicationEvents.Opsys != OperationSystem.Android) { destinationPath = Path.Combine(Application.dataPath, destpathf); }
if (toMainpath == ID_toPath.DataPath && CommunicationEvents.Opsys != OperationSystem.Android) { destinationPath = Path.Combine(Get_DataPath(), destpathf); }
else
{
destinationPath = Path.Combine(Application.persistentDataPath, destpathf);
......
......@@ -118,9 +118,10 @@ void start2_CheckOS_CheckConfig()
//Debug.Log("EndAdaption");
NetworkJSON_Load();
if (!checkDataPath() )//|| true)
Debug.Log("Todo: Prfen auf Bugs bzl DataPath");
//if (!checkDataPath())
if (!checkDataPath() && false)
Debug.Log("Todo: Prfen auf Bugs bzl DataPath");
if (!checkDataPath() || true)
{
ResetDataPath();
//Debug.Log("Info: DataPath Resetted");
......@@ -185,6 +186,16 @@ void checkOS2()
CommunicationEvents.Opsys = OperationSystem.Windows;
return;
}
if (Application.platform == RuntimePlatform.OSXPlayer)
{
CommunicationEvents.Opsys = OperationSystem.iOS;
return;
}
if (Application.platform == RuntimePlatform.WindowsPlayer)
{
CommunicationEvents.Opsys = OperationSystem.WindowsStoreApps;
return;
}
Debug.Log("Detecting OS: " + Application.platform + " -> " + CommunicationEvents.Opsys);
//Default:
......
......@@ -98,7 +98,7 @@ void UpdateUI_6()
{
case OperationSystem.Windows:
Opsys_ButtonT.GetComponent<Text>().text = "Windows optimized";
Opsys_ButtonT.GetComponent<Text>().text = "Windows/Desktop optimized";
Opsys_ButtonUT.GetComponent<Text>().text = "Press for changing optimzation";
setMouse();
break;
......@@ -106,11 +106,12 @@ void UpdateUI_6()
case OperationSystem.Android:
Opsys_ButtonT.GetComponent<Text>().text = "Android optimized: No mouse";
Opsys_ButtonT.GetComponent<Text>().text = "Android/Mobile optimized: No mouse, No Datapath";
Opsys_ButtonUT.GetComponent<Text>().text = "Press for changing optimzation";
setMouse();
break;
default:
Opsys_ButtonT.GetComponent<Text>().text = "Not optimized";
......
......@@ -4,10 +4,12 @@ For OperatingSystem Android: please register all Files in StreamingAssetLoader!
## StreamToDataPath:
All files and subfolders will be copied to DataPath.
Will be triggered on each start of the game.
Exception: Files with "meta" in the name.
## StreamToPersistentDataPath:
All files and subfolders will be copied to PersistentDataPath.
Will be triggered on first time installing the game or with the corresponding restart buttons.
Exception: Files with "meta" in the name.
......
1
\ No newline at end of file
DataPath:
Its location is the installation folder.
Files in this directory are not persistent.
They will be overwritten on each start of the game.
1
\ No newline at end of file
PersistantDataPath:
Its locations is the operating systems corresponding default user appdata folder.
Its informations are persistent.
They will be initialized on first start.
They can be resetted with the ingame reset buttons.
1
\ No newline at end of file
DataPath:
Its location is the installation folder.
Files in this directory are not persistent.
They will be overwritten on each start of the game.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment