From e33915b5783fd46cc7c792b3b42c867bf373f3cf Mon Sep 17 00:00:00 2001 From: Jens Date: Sat, 13 Mar 2021 00:40:59 +0100 Subject: [PATCH] Migration of old files finished. --- app/build.gradle | 4 +- .../com/jens/automation2/Miscellaneous.java | 58 ++++++++++++++++--- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values/strings.xml | 2 +- 4 files changed, 53 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4b8ef0e..6e6c303 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { compileSdkVersion 29 buildToolsVersion '29.0.2' useLibrary 'org.apache.http.legacy' - versionCode 98 - versionName "1.6.22" + versionCode 99 + versionName "1.6.23" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/jens/automation2/Miscellaneous.java b/app/src/main/java/com/jens/automation2/Miscellaneous.java index b54429a..9efb712 100644 --- a/app/src/main/java/com/jens/automation2/Miscellaneous.java +++ b/app/src/main/java/com/jens/automation2/Miscellaneous.java @@ -21,9 +21,6 @@ import android.provider.MediaStore; import android.provider.Settings.Secure; import android.util.Base64; import android.util.Log; -import android.widget.Toast; - -import androidx.core.app.NotificationCompat; import com.jens.automation2.location.LocationProvider; import com.jens.automation2.receivers.PhoneStatusListener; @@ -47,11 +44,14 @@ import org.xml.sax.SAXException; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; import java.io.StringReader; import java.lang.Thread.UncaughtExceptionHandler; import java.lang.reflect.InvocationTargetException; @@ -81,6 +81,8 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import androidx.core.app.NotificationCompat; + import static com.jens.automation2.AutomationService.NOTIFICATION_CHANNEL_ID; import static com.jens.automation2.AutomationService.channelName; @@ -340,8 +342,8 @@ public class Miscellaneous extends Service for (String f : foldersToTestArray) { - if (testFolder(f)) - { +// if (testFolder(f)) +// { String pathToUse = f + "/" + Settings.folderName; // Toast.makeText(getAnyContext(), "Using " + pathToUse + " to store settings and log.", Toast.LENGTH_LONG).show(); @@ -353,14 +355,24 @@ public class Miscellaneous extends Service { Miscellaneous.logEvent("i", "Path", "Found old path " + pathToUse + " for settings and logs. Migrating old files to new directory.", 2); - for (File moveFile : oldDirectory.listFiles()) - moveFile.renameTo(newDirectory); + for (File fileToBeMoved : oldDirectory.listFiles()) + { + File dstFile = new File(writeableFolderStringCache + "/" + fileToBeMoved.getName()); + + /* + For some stupid reason Android's file.moveTo can't move files between + mount points. That's why we have to copy it and delete the src if successful. + */ + + if(copyFileUsingStream(fileToBeMoved, dstFile)) + fileToBeMoved.delete(); + } String message = String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.filesHaveBeenMovedTo), newDirectory.getAbsolutePath()); - Miscellaneous.writeStringToFile(oldDirectory.getAbsolutePath() + "readme.txt", message); + Miscellaneous.writeStringToFile(oldDirectory.getAbsolutePath() + "/readme.txt", message); break migration; } - } +// } } } catch (Exception e) { @@ -1056,4 +1068,32 @@ public class Miscellaneous extends Service return null; } } + + public static boolean copyFileUsingStream(File source, File dest) throws IOException + { + boolean returnValue = false; + + InputStream is = null; + OutputStream os = null; + try + { + is = new FileInputStream(source); + os = new FileOutputStream(dest); + byte[] buffer = new byte[1024]; + int length; + while ((length = is.read(buffer)) > 0) + { + os.write(buffer, 0, length); + } + + returnValue = true; + } + finally + { + is.close(); + os.close(); + } + + return returnValue; + } } \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 124f8c3..4ba27e0 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -594,4 +594,5 @@ Dieses Gerät scheint kein Bluetooth zu haben. Sie können mit der Konfiguration fortfahren, aber es wird vermutlich keinen Effekt haben. Orte anlegen oder ändern veröffentlicht am + Automation benutzt jetzt ein anderes Verzeichnis, um Ihre Daten zu speichern. Alle Ihre Automation-Dateien wurden hierhin verschoben: \"%s\". Die Berechtigung für den externen Speicher wird nun nicht mehr benötigt; Sie können Sie entfernen. In einer künftigen Version wird sie entfernt werden. \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4eeccc8..13518f1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -605,5 +605,5 @@ published on Display application news on main screen Announcements about this app only, we\'re probably talking about 1-2 per year, not more. - Automation now uses another path to store your files. The existing ones have been moved. You can find them here: %s. + Automation now uses another path to store your files. All your Automation-files have been moved here: \"%s\". The external storage permission is not required anymore; you can revoke it. It will be removed in a future version. \ No newline at end of file