diff --git a/.idea/deviceManager.xml b/.idea/deviceManager.xml new file mode 100644 index 0000000..91f9558 --- /dev/null +++ b/.idea/deviceManager.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 317bc7e..dbc8e99 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,12 +3,12 @@ plugins { } android { - compileSdk 36 + compileSdk 34 defaultConfig { applicationId "be.gyu.android.server.ftp" minSdk 21 - targetSdk 36 + targetSdk 34 versionCode 1 versionName "1.0" diff --git a/app/src/main/java/be/gyu/android/server/ftp/FTPFileSystem.java b/app/src/main/java/be/gyu/android/server/ftp/FTPFileSystem.java index 70f84f3..90aa352 100644 --- a/app/src/main/java/be/gyu/android/server/ftp/FTPFileSystem.java +++ b/app/src/main/java/be/gyu/android/server/ftp/FTPFileSystem.java @@ -17,25 +17,47 @@ public class FTPFileSystem { private File currentDirectory; public FTPFileSystem() { - // Use external storage public directory as root - // In production, you might want to use app-specific directory or allow user to choose - File externalStorage = Environment.getExternalStorageDirectory(); - this.rootDirectory = new File(externalStorage, "FTPServer"); + this(null); + } - // Create root directory if it doesn't exist - if (!rootDirectory.exists()) { - if (rootDirectory.mkdirs()) { - Log.i(TAG, "Root directory created: " + rootDirectory.getAbsolutePath()); + public FTPFileSystem(String rootDirectoryPath) { + if (rootDirectoryPath != null && !rootDirectoryPath.isEmpty()) { + // Use user-specified directory + File userDir = new File(rootDirectoryPath); + if (userDir.exists() && userDir.isDirectory()) { + this.rootDirectory = userDir; + Log.i(TAG, "Using user-specified root: " + rootDirectory.getAbsolutePath()); } else { - Log.w(TAG, "Failed to create root directory, using external storage root"); - this.rootDirectory = externalStorage; + Log.w(TAG, "User-specified directory does not exist: " + rootDirectoryPath); + this.rootDirectory = getDefaultRootDirectory(); } + } else { + // Use default directory + this.rootDirectory = getDefaultRootDirectory(); } this.currentDirectory = rootDirectory; Log.d(TAG, "File system initialized. Root: " + rootDirectory.getAbsolutePath()); } + private File getDefaultRootDirectory() { + File externalStorage = Environment.getExternalStorageDirectory(); + File ftpServerDir = new File(externalStorage, "FTPServer"); + + // Create root directory if it doesn't exist + if (!ftpServerDir.exists()) { + if (ftpServerDir.mkdirs()) { + Log.i(TAG, "Root directory created: " + ftpServerDir.getAbsolutePath()); + return ftpServerDir; + } else { + Log.w(TAG, "Failed to create root directory, using external storage root"); + return externalStorage; + } + } else { + return ftpServerDir; + } + } + public String getCurrentPath() { String relativePath = getRelativePath(currentDirectory); return relativePath.isEmpty() ? "/" : "/" + relativePath;