Ejemplo n.º 1
0
        public string GetDirectories(string path)
        {
            DebugHandler.TraceMessage("GetDirectories Called", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage("Directory Path: " + path, DebugSource.TASK, DebugType.PARAMETERS);


            try
            {
                string[] dirs = Directory.GetDirectories(path);

                JsonDirectories      tosendover          = new JsonDirectories();
                List <JsonDirectory> directorieswithpath = new List <JsonDirectory>();
                foreach (string directory in dirs)
                {
                    JsonDirectory directorywithpath = new JsonDirectory
                    {
                        dirname = directory.Replace(Path.GetDirectoryName(directory) + Path.DirectorySeparatorChar, ""),
                        path    = directory
                    };
                    tosendover.directories.Add(directorywithpath);
                }
                return(tosendover.ToJson());
            }
            catch (Exception e)
            {
                DebugHandler.TraceMessage("Failed getting directories: " + e.ToString(), DebugSource.TASK, DebugType.WARNING);

                JsonError jsonError = new JsonError
                {
                    type         = "get_drives_error",
                    errortype    = "exception",
                    errormessage = "Could not get drives, see log.",
                    exception    = e.ToString()
                };

                return(jsonError.ToJson());
            }
        }
Ejemplo n.º 2
0
        public string GetDrives()
        {
            DebugHandler.TraceMessage("GetDrives Called", DebugSource.TASK, DebugType.ENTRY_EXIT);
            try
            {
                JsonDirectories directories = new JsonDirectories();

#if __ANDROID__
#if DEBUG
#warning Compiling android code!
#endif

                DebugHandler.TraceMessage("Running Android Code!", DebugSource.TASK, DebugType.INFO);


                string onlyAvailablePath = "/storage/";
                if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M)
                {
                    string[] dirs = Directory.GetDirectories("/storage/");

                    foreach (string dir in dirs)
                    {
                        if (dir.Contains("-"))
                        {
                            onlyAvailablePath = Path.Combine(dir, "/Android/data/LittleWeeb.LittleWeeb/files");
                            break;
                        }
                    }
                }


                JsonDirectory directory = new JsonDirectory();
                directory.path    = onlyAvailablePath;
                directory.dirname = "External Storage if Present.";

                directories.directories.Add(directory);

                directory         = new JsonDirectory();
                directory.path    = Android.OS.Environment.RootDirectory.AbsolutePath;
                directory.dirname = "Internal Root Directory";

                directories.directories.Add(directory);


                return(directories.ToJson());
#else
                DebugHandler.TraceMessage("Running Windows Code!", DebugSource.TASK, DebugType.INFO);
                DriveInfo[] allDrives = DriveInfo.GetDrives();
                foreach (DriveInfo drive in allDrives)
                {
                    JsonDirectory directorywithpath = new JsonDirectory
                    {
                        dirname = drive.Name,
                        path    = drive.Name
                    };
                    directories.directories.Add(directorywithpath);
                }
                return(directories.ToJson());
#endif
            }
            catch (Exception e)
            {
                DebugHandler.TraceMessage("Failed to get drives: " + e.ToString(), DebugSource.TASK, DebugType.WARNING);

                JsonError error = new JsonError
                {
                    type         = "get_drives_error",
                    errortype    = "exception",
                    errormessage = "Could not get drives, see log.",
                    exception    = e.ToString()
                };

                return(error.ToJson());
            }
        }