Beispiel #1
0
        private void cmbProviderList_TextChanged(object sender, EventArgs e)
        {
            //set remotename and remoteprovider
            string nRemoteName     = "";
            string nRemoteProvider = cmbProviderList.Text;

            string[] rcmdlist = { };

            //hide the combobox cos it's no longer needed
            cmbProviderList.Visible = false;

            //if user doesnt enter a valid remote name, keep asking
            while (String.IsNullOrEmpty(nRemoteName.Trim()))
            {
                nRemoteName = PromptGenerator.ShowDialog("Remote Name:", "Please enter an alphanumeric name for the remote");
            }

            //build command list
            if (nRemoteProvider == "amazon cloud drive")
            {
                rcmdlist = new[] { "n", nRemoteName, nRemoteProvider, "\r\n", "\r\n", "y", "MSG: Please Accept the oauth req in your browser before continuing", "y", "q" };
            }
            else if (nRemoteProvider == "dropbox")
            {
                rcmdlist = new[] { "n", nRemoteName, nRemoteProvider, "\r\n", "\r\n", @"OPN|https\:\/\/www\.dropbox(.*?)response_type=code", "REQ:Dropbox Code", "y", "q", "q" };
            }
            else if (nRemoteProvider == "drive")
            {
                rcmdlist = new[] { "n", nRemoteName, nRemoteProvider, "\r\n", "\r\n", "y", "MSG: Please Accept the oauth req in your browser before continuing", "y", "q" };
            }
            else if (nRemoteProvider == "hubic")
            {
                rcmdlist = new[] { "n", nRemoteName, nRemoteProvider, "\r\n", "\r\n", "y", "MSG: Please Accept the oauth req in your browser before continuing", "y", "q" };
            }
            else if (nRemoteProvider == "onedrive")
            {
                rcmdlist = new[] { "n", nRemoteName, nRemoteProvider, "\r\n", "\r\n", "y", "MSG: Please Accept the oauth req in your browser before continuing", "y", "q" };
            }
            else if (nRemoteProvider == "yandex")
            {
                rcmdlist = new[] { "n", nRemoteName, nRemoteProvider, "\r\n", "\r\n", "y", "MSG: Please Accept the oauth req in your browser before continuing", "y", "q" };
            }
            else
            {
                MessageBox.Show("Currently this remote is not supported, please try one of the following:\r\n\r\nACD, dropbox, drive, hubic, onedrive, yandex");
                return;
            }

            //tell user whats happening
            MessageBox.Show("Making a new '" + nRemoteProvider + "' config, called '" + nRemoteName + "'");

            //run command
            internalExecHandler.Execute("config", "", "config", null, rcmdlist);

            //refresh list view
            loadConfigs();
        }
Beispiel #2
0
        private void btnNewFileAssoc_Click(object sender, EventArgs e)
        {
            string extension = PromptGenerator.ShowDialog("Extension (with dot):", "New Association");
            string assoc     = PromptGenerator.ShowDialog("Command:", "New Association");
            string existingDefinedFiletypes = iniSettings.Read("definedFiletypes");

            iniSettings.Write("definedFiletypes", existingDefinedFiletypes + "," + extension);
            iniSettings.Write(extension, assoc, "FTA");
            getAssocs();
        }
        public void ctxtExplorerContext_NewFolder_Click(object sender, EventArgs e)
        {
            string dirName = PromptGenerator.ShowDialog("Folder Name:", "New Folder");

            internalExecHandler.Execute("mkdir", iniSettings.Read("rcloneRemote") + ":\"" + rcloneExplorer.remoteCD + "\\" + dirName + "\"");
            //refresh
            if (iniSettings.Read("refreshAutomatically") == "true")
            {
                refreshlstExplorer();
            }
        }
        public void ctxtExplorerContext_Rename_Click(object sender, EventArgs e)
        {
            ListView lstExplorer = rcloneExplorer.myform.Controls.Find("lstExplorer", true)[0] as ListView;
            string   oldName     = rcloneExplorer.remoteCD + lstExplorer.SelectedItems[0].SubItems[3].Text;
            string   newName     = PromptGenerator.ShowDialog("Folder Name:", "New Folder", oldName);

            internalExecHandler.Execute("moveto", iniSettings.Read("rcloneRemote") + ":\"" + oldName + "\" " + iniSettings.Read("rcloneRemote") + ":\"" + newName + "\"");
            //refresh
            if (iniSettings.Read("refreshAutomatically") == "true")
            {
                refreshlstExplorer();
            }
        }
Beispiel #5
0
        public string Execute(string command, string arguments, string operation = null, string prepend = null, string[] rcmdlist = null)
        {
            output = null;
            string rcloneLogs  = "";
            string threadIdTxt = DateTime.Now.Ticks.ToString().Substring(DateTime.Now.Ticks.ToString().Length - 9);
            int    threadId    = Convert.ToInt32(threadIdTxt);

            //check for verbose logging
            if (operation == "sync")
            {
                rcloneLogs = " --log-file sync.log --verbose";
            }
            else if (iniSettings.Read("rcloneVerbose") == "true")
            {
                rcloneLogs = " --log-file rclone.log --verbose";
            }

            //set up cmd to call rclone
            Process process = new Process();

            process.StartInfo.FileName = "cmd.exe";
            process.StartInfo.EnvironmentVariables["RCLONE_CONFIG_PASS"] = iniSettings.Read("rcloneConfigPass");
            process.StartInfo.Arguments              = "/c " + prepend + "rclone.exe " + command + " " + arguments + rcloneLogs + " --stats 5s";
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.StandardErrorEncoding  = Encoding.UTF8;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.StandardOutputEncoding = Encoding.UTF8;
            process.StartInfo.RedirectStandardInput  = true;
            process.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            process.StartInfo.WorkingDirectory       = AppDomain.CurrentDomain.BaseDirectory;
            process.OutputDataReceived += (sender, args) => proc_OutputDataReceived(sender, args);
            process.ErrorDataReceived  += (sender, args) => proc_ErrorDataReceived(sender, args, operation, threadId);
            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            //log command
            if (rcloneExplorer.consoleEnabled)
            {
                rcloneExplorer.rawOutputBuffer += "Thread: " + Thread.CurrentThread.ManagedThreadId + ": STDIN: " + process.StartInfo.FileName + " " + process.StartInfo.Arguments + Environment.NewLine;
            }

            //log process ID for uploads, downloads and sync operations
            if (!String.IsNullOrEmpty(operation))
            {
                if (operation == "passcheck")
                {
                    //check if config has password
                    process.WaitForExit();
                    if (output.Contains("password:"******"up")
                {
                    //log the process in the uploading list with race conditions galore
                    int    id         = uploadsHandler.uploading.Count - 1;
                    string percentage = uploadsHandler.uploading[id][2];
                    string speed      = uploadsHandler.uploading[id][3];
                    //list should be {PID, Name, Percent, Speed}
                    uploadsHandler.uploading[id][0] = process.Id.ToString();
                    uploadsHandler.uploading[id][1] = "";
                    uploadsHandler.uploading[id][2] = percentage;
                    uploadsHandler.uploading[id][3] = speed;
                    //add entry in erroutput dictionary
                    if (!errOutput.ContainsKey(threadId))
                    {
                        errOutput.Add(threadId, "");
                    }
                    //monitor process output
                    while (!process.HasExited)
                    {
                        if (errOutput[threadId] != null)
                        {
                            try
                            {
                                percentage = Regex.Match(errOutput[threadId], @"\d+(?=%)% done", RegexOptions.RightToLeft).Value;
                                speed      = Regex.Match(errOutput[threadId], @"[ \t]+\d+(.\d+)? [a-zA-Z]+[/s]s", RegexOptions.RightToLeft).Value;
                                if (!string.IsNullOrEmpty(percentage))
                                {
                                    uploadsHandler.uploading[id][2] = percentage;
                                }
                                if (!string.IsNullOrEmpty(speed))
                                {
                                    uploadsHandler.uploading[id][3] = speed;
                                }
                            }
                            catch (NullReferenceException e)
                            {
                                Console.Write(e);
                            }
                            catch (ArgumentNullException e)
                            {
                                Console.Write(e);
                            }
                            errOutput[threadId] = null;
                        }
                    }
                    if (process.HasExited)
                    {
                        uploadsHandler.uploading[id][2] = "100%";
                        errOutput.Remove(threadId);
                        return("");
                    }
                }
                else if (operation == "down")
                {
                    int    id         = downloadsHandler.downloading.Count - 1;
                    string percentage = downloadsHandler.downloading[id][2];
                    string speed      = downloadsHandler.downloading[id][3];
                    //list should be {PID, Name, Percent, Speed}
                    downloadsHandler.downloading[id][0] = process.Id.ToString();
                    downloadsHandler.downloading[id][1] = "";
                    downloadsHandler.downloading[id][2] = percentage;
                    downloadsHandler.downloading[id][3] = speed;
                    //add entry in erroutput dictionary
                    if (!errOutput.ContainsKey(threadId))
                    {
                        errOutput.Add(threadId, "");
                    }
                    //monitor process output
                    while (!process.HasExited)
                    {
                        if (errOutput[threadId] != null)
                        {
                            try
                            {
                                percentage = Regex.Match(errOutput[threadId], @"\d+(?=%)% done", RegexOptions.RightToLeft).Value;
                                speed      = Regex.Match(errOutput[threadId], @"[ \t]+\d+(.\d+)? [a-zA-Z]+[/s]s", RegexOptions.RightToLeft).Value;
                                if (!string.IsNullOrEmpty(percentage))
                                {
                                    downloadsHandler.downloading[id][2] = percentage;
                                }
                                if (!string.IsNullOrEmpty(speed))
                                {
                                    downloadsHandler.downloading[id][3] = speed;
                                }
                            }
                            catch (NullReferenceException e)
                            {
                                Console.Write(e);
                            }
                            catch (ArgumentNullException e)
                            {
                                Console.Write(e);
                            }
                            errOutput[threadId] = null;
                        }
                    }
                    if (process.HasExited)
                    {
                        downloadsHandler.downloading[id][2] = "100%";
                        errOutput.Remove(threadId);
                        return("");
                    }
                }
                else if (operation == "sync")
                {
                    //log the process in the syncing list
                    syncingHandler.syncingPID = process.Id;
                }
                else if (operation == "config")
                {
                    //iterate through the commands needed to set the remote up (its different per remote)
                    while (String.IsNullOrEmpty(output))
                    {
                        Thread.Sleep(100);
                    }

                    foreach (string rcmd in rcmdlist)
                    {
                        //the remote setup has asked to show a message
                        if (rcmd.Contains("MSG: "))
                        {
                            while (!output.Contains("Got code"))
                            {
                                MessageBox.Show(rcmd);
                            }
                        }
                        //the remote setup has hasked to open a url
                        else if (rcmd.Contains("OPN|"))
                        {
                            //grab the predefined regex
                            string regexp = rcmd.Split('|')[1];
                            String url    = "";
                            while (String.IsNullOrEmpty(url))
                            {
                                url = Regex.Match(output, regexp).Value;
                            }
                            //open the url
                            Process.Start(url);
                        }
                        //the remote setup has asked for some information
                        else if (rcmd.Contains("REQ:"))
                        {
                            string requiredinput = "";
                            while (String.IsNullOrEmpty(requiredinput))
                            {
                                requiredinput = PromptGenerator.ShowDialog(rcmd, "");
                            }
                            process.StandardInput.WriteLine(requiredinput);
                        }
                        //the remote setup just wants to send some text
                        else
                        {
                            process.StandardInput.WriteLine(rcmd);
                        }
                        //sleep between operations
                        System.Threading.Thread.Sleep(100);
                    }
                }
            }
            else
            {
                process.WaitForExit();
            }

            //return output
            if (String.IsNullOrEmpty(output))
            {
                output = "";
            }
            return(output.Replace("\r", ""));
        }
        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;
            }
        }