Beispiel #1
0
        private void loadConfigs()
        {
            lstConfigs.Items.Clear();
            //get the output of config command, and echo q to quit it so the process doesnt hang
            string[] output = internalExecHandler.Execute("config", "", null, "echo q |").Split('\n');
            bool     currentlyOnRemoteList = false;

            //iterate through each all the output line by line (inefficient)
            foreach (string str in output)
            {
                //rclone uses three equals signs to seperate header from output, so start reading rows after that
                if (str.Contains("==="))
                {
                    currentlyOnRemoteList = true;
                }
                //rclone has a blank row after all the remotes are listed, so stop reading there
                else if (currentlyOnRemoteList && str == "")
                {
                    currentlyOnRemoteList = false;
                }
                else if (currentlyOnRemoteList)
                {
                    //iterate through the list of known providers
                    foreach (string provider in providers)
                    {
                        //really hacky way to single out the provider column
                        if (str.Contains("  " + provider))
                        {
                            //remove the remote provider name and trim the whitespace between the columns
                            string remotename = str.Replace("  " + provider, "").Trim();
                            //we've already identified that the string contains the current provider being iterated, so store it
                            string remoteprovider = provider;
                            //add this entry to the list and break
                            lstConfigs.Items.Add(new ListViewItem(new string[] { remotename, remoteprovider }));
                            break;
                        }
                    }
                }
            }
        }
        public void initRcloneSettings()
        {
            //check local dir for rclone
            if (!System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\rclone.exe"))
            {
                //rclone not found, quit
                MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory + "\\rclone.exe \r\nfile not found!");
                Environment.Exit(0);
            }

            if (System.IO.File.Exists("rcloneExplorer.ini"))
            {
                //config found, checking for settings
                if (string.IsNullOrEmpty(iniSettings.Read("rcloneRemote")))
                {
                    MessageBox.Show("ERR: No default remote selected! Please choose a remote.\r\n\r\nLoading config, this may take a minute...");
                    rcloneExplorer.initialSetup = true;
                }
                else
                {
                    //config seems ok so read config settings
                    iniSettings.Read("rcloneRemote");
                }
                if (!iniSettings.KeyExists("definedFiletypes"))
                {
                    iniSettings.Write("definedFiletypes", ".mkv,.avi,.mp4,.mov");
                    iniSettings.Write(".mkv", "ffplay.exe -", "FTA");
                    iniSettings.Write(".avi", "ffplay.exe -", "FTA");
                    iniSettings.Write(".mp4", " > file.mp4 && ffplay file.mp4 && del file.mp4", "FTA");
                    iniSettings.Write(".mov", "\"" + @"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" + "\" -", "FTA");
                }
            }
            else
            {
                //file not found!
                iniSettings.Write("rcloneRemote", "");
                iniSettings.Write("rcloneVerbose", "false");
                iniSettings.Write("refreshAutomatically", "false");
                iniSettings.Write("rcloneSyncSource", "");
                iniSettings.Write("rcloneSyncDestination", "");
                iniSettings.Write("rcloneSyncEnabled", "false");
                iniSettings.Write("rcloneSyncFrequency", "0");
                iniSettings.Write("rcloneSyncSvC", "copy");
                iniSettings.Write("rcloneSyncBandwidthLimit", "0");
                iniSettings.Write("rcloneSyncMinFileSize", "0");
                iniSettings.Write("rcloneSyncMaxFileSize", "0");
                string configpass = "";
                string results    = internalExecHandler.Execute("version", "", "passcheck");
                if (rcloneExplorer.configEncrypted)
                {
                    configpass = PromptGenerator.ShowDialog("config password:"******"Encrypted config check");
                }
                iniSettings.Write("rcloneConfigPass", configpass);
                iniSettings.Write("definedFiletypes", ".mkv,.avi,.mp4,.mov");
                iniSettings.Write(".mkv", "ffplay.exe -", "FTA");
                iniSettings.Write(".avi", "ffplay.exe -", "FTA");
                iniSettings.Write(".mp4", " > file.mp4 && ffplay file.mp4 && del file.mp4", "FTA");
                iniSettings.Write(".mov", "\"" + @"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" + "\" -", "FTA");
                MessageBox.Show("ERR: No ini file found!\r\n\r\nLoading config screen, this may take a minute...");
                rcloneExplorer.initialSetup = true;
            }
        }
        public void lstExplorer_DragDrop(DragEventArgs e)
        {
            ListView lstUploads = rcloneExplorer.myform.Controls.Find("lstUploads", true)[0] as ListView;

            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            foreach (string file in files)
            {
                // get the file attributes for file or directory
                FileAttributes attr = File.GetAttributes(file);

                //detect whether its a directory or file
                if (attr.HasFlag(FileAttributes.Directory))
                {
                    //its a folder
                    MessageBox.Show("Uploading directory: " + file);
                    //in a new thread start uploading the file
                    new Thread(() =>
                    {
                        //get directory name so it can be sent to rclone process
                        string dirName = new DirectoryInfo(file).Name;
                        //copy local path to rclone folder + directory name
                        internalExecHandler.Execute("copy", "\"" + file + "\" " + iniSettings.Read("rcloneRemote") + ":\"" + rcloneExplorer.remoteCD + dirName + "\"", "up");
                    }).Start();
                }
                else
                {
                    //its a file
                    MessageBox.Show("Uploading file: " + file);
                    //store the path selected via the dialog and filename taken from the selected entry
                    string[] newuploadentry = new string[] { "", file, "0%", "0 Bytes/s" };
                    //store the info into the download history list
                    uploadsHandler.uploading.Add(newuploadentry);
                    //add tolistview
                    lstUploads.Items.Add(new ListViewItem(newuploadentry));
                    //in a new thread start uploading the file
                    new Thread(() =>
                    {
                        //copy local path to rclone folder
                        internalExecHandler.Execute("copy", "\"" + file + "\" " + iniSettings.Read("rcloneRemote") + ":\"" + rcloneExplorer.remoteCD + "\"", "up");
                    }).Start();
                }
            }
        }