Changed settings location to regular data folder. Migration of files in existing installations pending.

This commit is contained in:
2021-03-07 23:45:47 +01:00
parent f9cf3356e7
commit d803d57af1
8 changed files with 83 additions and 68 deletions

View File

@ -313,42 +313,52 @@ public class Miscellaneous extends Service
{
if(writeableFolderStringCache == null)
{
String testPath = null;
File folder = null;
try
if(!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, Miscellaneous.getAnyContext()))
{
String[] foldersToTestArray = new String[]
{
Environment.getExternalStorageDirectory().getAbsolutePath(),
"/storage/emulated/0",
"/HWUserData",
"/mnt/sdcard"
};
// Use the app-specific folder as new default.
for(String f : foldersToTestArray)
writeableFolderStringCache = Miscellaneous.getAnyContext().getFilesDir().getAbsolutePath();
return writeableFolderStringCache;
}
else
{
//TODO: We have the storage permission, probably because it's an old installation. Files should be migrated to app-specific folder.
String testPath = null;
File folder = null;
try
{
if (testFolder(f))
String[] foldersToTestArray = new String[]
{
Environment.getExternalStorageDirectory().getAbsolutePath(),
"/storage/emulated/0",
"/HWUserData",
"/mnt/sdcard"
};
for (String f : foldersToTestArray)
{
String pathToUse = f + "/" + Settings.folderName;
Miscellaneous.logEvent("i", "Path", "Using " + pathToUse + " to store settings and log.", 2);
if (testFolder(f))
{
String pathToUse = f + "/" + Settings.folderName;
Miscellaneous.logEvent("i", "Path", "Using " + pathToUse + " to store settings and log.", 2);
// Toast.makeText(getAnyContext(), "Using " + pathToUse + " to store settings and log.", Toast.LENGTH_LONG).show();
return pathToUse;
return pathToUse;
}
else
Miscellaneous.logEvent("e", "getWritableFolder", folder.getAbsolutePath() + " does not exist and could not be created.", 3);
}
else
Miscellaneous.logEvent("e", "getWritableFolder", folder.getAbsolutePath() + " does not exist and could not be created.", 3);
} catch (Exception e)
{
Log.w("getWritableFolder", folder + " not writable.");
}
// do not change to logEvent() - we can't write
Toast.makeText(getAnyContext(), "No writable folder could be found.", Toast.LENGTH_LONG).show();
Log.e("getWritableFolder", "No writable folder could be found.");
return null;
}
catch(Exception e)
{
Log.w("getWritableFolder", folder + " not writable.");
}
// do not change to logEvent() - we can't write
Toast.makeText(getAnyContext(), "No writable folder could be found.", Toast.LENGTH_LONG).show();
Log.e("getWritableFolder", "No writable folder could be found.");
return null;
}
else
return writeableFolderStringCache;