1717using Java . Util . Logging ;
1818using QuestAppVersionSwitcher . Core ;
1919using File = System . IO . File ;
20- using Logger = ComputerUtils . Android . Logging . Logger ;
2120
2221namespace QuestAppVersionSwitcher
2322{
@@ -30,7 +29,6 @@ public static void openDirectory(string dirInExtenalStorage)
3029 {
3130 FileManager . CreateDirectoryIfNotExisting ( dirInExtenalStorage ) ;
3231 }
33- Logger . Log ( RemapPathForApi300OrAbove ( dirInExtenalStorage ) ) ;
3432 Intent intent = new Intent ( Intent . ActionOpenDocumentTree )
3533 . PutExtra (
3634 DocumentsContract . ExtraInitialUri ,
@@ -41,7 +39,6 @@ public static void openDirectory(string dirInExtenalStorage)
4139 public static string RemapPathForApi300OrAbove ( string path )
4240 {
4341 string suffix = path ;
44- Logger . Log ( suffix ) ;
4542 if ( suffix . StartsWith ( "/sdcard" ) ) suffix = suffix . Substring ( "/sdcard" . Length ) ;
4643 if ( path . StartsWith ( Environment . ExternalStorageDirectory . AbsolutePath ) )
4744 {
@@ -57,33 +54,32 @@ public static string RemapPathForApi300OrAbove(string path)
5754 public static void Copy ( string from , string to )
5855 {
5956 Stream file = GetOutputStream ( to ) ;
60- StreamWriter sw = new StreamWriter ( file ) ;
61- sw . Write ( File . ReadAllBytes ( from ) ) ;
62- sw . Dispose ( ) ;
57+ file . Write ( File . ReadAllBytes ( from ) ) ;
58+ file . Close ( ) ;
59+ file . Dispose ( ) ;
6360 }
6461
6562 public static void CreateDirectory ( string dir )
6663 {
6764 DocumentFile parent = GetAccessToFile ( Directory . GetParent ( dir ) . FullName ) ;
68- Logger . Log ( parent . CanWrite ( ) . ToString ( ) ) ;
6965 parent . CreateDirectory ( Path . GetFileName ( dir ) ) ;
7066 }
7167
7268 /// <summary>
73- ///
69+ /// ONLY WORKS FOR /sdcard/Android/data/...!!!!!!!
7470 /// </summary>
7571 /// <param name="dir">Expected as /sdcard/Android/data/...</param>
7672 /// <returns></returns>
7773 public static DocumentFile GetAccessToFile ( string dir )
7874 {
79- Logger . Log ( "Trying to get access to " + dir ) ;
8075 string start = "/sdcard/Android/data/" + CoreService . coreVars . currentApp ;
8176 string diff = dir . Replace ( start + "/" , "" ) ;
8277 string [ ] dirs = diff . Split ( '/' ) ;
8378 DocumentFile startDir = DocumentFile . FromTreeUri ( AndroidCore . context , Uri . Parse ( RemapPathForApi300OrAbove ( start ) . Replace ( "com.android.externalstorage.documents/document/" , "com.android.externalstorage.documents/tree/" ) ) ) ;
8479 DocumentFile currentDir = startDir ;
8580 foreach ( string dirName in dirs )
8681 {
82+ if ( currentDir . FindFile ( dirName ) == null ) currentDir . CreateDirectory ( dirName ) ; // Create directory if it doesn't exist
8783 currentDir = currentDir . FindFile ( dirName ) ;
8884 }
8985 return currentDir ;
@@ -106,7 +102,6 @@ public static void Delete(string path)
106102
107103 public static void CreateDirectoryIfNotExisting ( string path )
108104 {
109- Logger . Log ( "Creating directory " + path + " if it doesn't exist" ) ;
110105 DocumentFile directory = GetAccessToFile ( Directory . GetParent ( path ) . FullName ) ;
111106 string name = Path . GetFileName ( path ) ;
112107 if ( directory . FindFile ( name ) == null ) directory . CreateDirectory ( name ) ;
@@ -133,7 +128,6 @@ public void OnActivityResult(Object result)
133128 {
134129 if ( activityResult . Data . Data != null )
135130 {
136- Logger . Log ( activityResult . Data . Data . ToString ( ) ) ;
137131 AndroidCore . context . ContentResolver . TakePersistableUriPermission (
138132 activityResult . Data . Data ,
139133 ActivityFlags . GrantReadUriPermission | ActivityFlags . GrantWriteUriPermission ) ;
0 commit comments