Example #1
0
        private async void AutoDownloadFiles(PutioFile putiofile)
        {
            var response = await filemgr.List(putiofile.id);

            List <string> allowed_extensions = new List <string>();

            allowed_extensions.AddRange(putiofile.autodownload_extensions.Split(',').ToArray());

            foreach (JObject jobject in response)
            {
                var file = SetPutioFile(jobject);
                file.autodownload_extensions = putiofile.autodownload_extensions;
                file.autodownload_minsize    = putiofile.autodownload_minsize;
                if (file.file_type == "FOLDER")
                {
                    AutoDownloadFiles(file);
                }
                else
                {
                    var match = allowed_extensions.FirstOrDefault(filext => filext.Contains(GetFileExtension(file.name)));
                    if (match != null & file.autodownload_minsize <= Convert.ToInt64(file.size))
                    {
                        QueueDownload(file);
                    }
                }
            }
        }
        private void InitializeControls()
        {
            OAuthToken = Properties.Settings.Default.OAuthToken;

            filemgr = new Files(OAuthToken);
            zipmgr  = new Zips(OAuthToken);
            trfrmgr = new Transfers(OAuthToken);

            var root = new PutioFile("0", "putio files");

            treeViewPutioFiles.Nodes.Clear();
            rootnode     = treeViewPutioFiles.Nodes.Add("putio files");
            rootnode.Tag = root;

            treeViewPutioFiles.ShowNodeToolTips = Properties.Settings.Default.ShowToolTips;
            treeViewPutioFiles.SelectedNode     = treeViewPutioFiles.Nodes[0];


            splitContainerFiles.Panel2Collapsed = Properties.Settings.Default.ShowAutoDownloads;
            splitContainer1.Panel2Collapsed     = Properties.Settings.Default.ShowManager;

            TimeWorker.DoWork                    += TimeWorker_DoWork;
            TimeWorker.ProgressChanged           += TimeWorker_ReportProgress;
            TimeWorker.WorkerReportsProgress      = true;
            TimeWorker.WorkerSupportsCancellation = true;
            TimeWorker.RunWorkerCompleted        += TimeWorker_Complete;
        }
        private async void zipDownloadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var selectedfile = treeViewPutioFiles.SelectedNode.Tag as PutioFile;

            string zipstatus          = "";
            var    createzip_response = await zipmgr.CreateZip(selectedfile.id);

            string    zipid   = JObject.Parse(createzip_response)["zip_id"].ToString();
            PutioFile zipfile = new PutioFile(zipid, selectedfile.name + ".zip");

            zipfile.file_type = "ZIP";

            do
            {
                var zip_properties = await zipmgr.GetZip(zipid);

                zipstatus = zip_properties["zip_status"].ToString();
                if (zipstatus == "DONE")
                {
                    zipfile.downloadlink = new Uri(zip_properties["url"].ToString());
                }
            } while (zipstatus != "DONE");

            QueueDownload(zipfile);
        }
 private void PrintPutioProperties(PutioFile putiofile)
 {
     Console.WriteLine("===================");
     Console.WriteLine("filename: " + putiofile.name);
     Console.WriteLine("fileid: " + putiofile.id);
     Console.WriteLine("parent_id: " + putiofile.parent_id);
     Console.WriteLine("filetype: " + putiofile.file_type);
 }
        // Initalizers

        private void CstripDownload_Click(object sender, EventArgs e, PutioFile file)
        {
            if (file.webcilent.IsBusy)
            {
                Console.WriteLine("download canceled");
                file.webcilent.CancelAsync();
            }
        }
        private async void treeViewPutioFiles_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            treeViewPutioFiles.SelectedNode = e.Node;
            PutioFile file = e.Node.Tag as PutioFile;

            if (e.Node != rootnode)
            {
                UpdateTreeView(await filemgr.List(file.id), e.Node);
            }
        }
Example #7
0
 private bool AlreadyDownloading(PutioFile putiofile)
 {
     foreach (DataGridViewRow row in dataGridViewDownloads.Rows)
     {
         if (row.Cells["ColumnFile"].Value.ToString() == putiofile.name)
         {
             return(true);
         }
     }
     return(false);
 }
        // Methods and Modules

        private async void DeleteFile(PutioFile inPutioFile)
        {
            var deletemessage = await filemgr.Delete(inPutioFile.id);

            string status = JObject.Parse(deletemessage)["status"].ToString();

            if (status == "OK")
            {
                if (inPutioFile.file != null)
                {
                    treeViewPutioFiles.Nodes.Remove(inPutioFile.file);
                }
            }
        }
        private PutioFile SetPutioFile(JObject file)
        {
            var putiofile = new PutioFile(file["id"].ToString(), file["name"].ToString());

            putiofile.parent_id     = file["parent_id"].ToString();
            putiofile.content_type  = file["content_type"].ToString();
            putiofile.file_type     = file["file_type"].ToString();
            putiofile.download_path = Properties.Settings.Default.DownloadDirectory + @"\" + putiofile.name;
            putiofile.size          = file["size"].ToString();
            if (putiofile.content_type != "FOLDER")
            {
                putiofile.downloadlink = new Uri(urlPutioApi + "files/" + putiofile.id + "/download?oauth_token=" + OAuthToken);
            }

            return(putiofile);
        }
Example #10
0
        private void QueueDownload(PutioFile putiofile)
        {
            if (!AlreadyDownloading(putiofile))
            {
                string started = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
                string path    = Properties.Settings.Default.DownloadDirectory + @"\" + putiofile.name;

                dataGridViewDownloads.Rows.Add(putiofile.name, putiofile.file_type, started, "", "Not Started");
                DataGridViewRow newDownloadRow = dataGridViewDownloads.Rows[dataGridViewDownloads.Rows.Count - 1];

                putiofile.rowinque      = newDownloadRow;
                putiofile.download_path = path;

                FileDownloads.Enqueue(putiofile);
                DownloadFile();
            }
        }
Example #11
0
        private void UpdateTreeView(JArray inJArrFiles, TreeNode node)
        {
            node.Nodes.Clear();
            foreach (JObject file in inJArrFiles)
            {
                string message = null;

                var putiofile = new PutioFile(file["id"].ToString(), file["name"].ToString());
                putiofile.parent_id    = file["parent_id"].ToString();
                putiofile.content_type = file["content_type"].ToString();
                putiofile.file_type    = file["file_type"].ToString();
                //PrintPutioProperties(putiofile);

                TreeNode newnode = node.Nodes.Add(putiofile.name);
                newnode.Tag    = putiofile;
                putiofile.file = newnode;

                // set tooltip node text to the files properties
                foreach (var property in file)
                {
                    message += property.Key.ToString().ToLower() + ": " + property.Value.ToString().ToLower() + Environment.NewLine;
                }

                newnode.ToolTipText = message;

                if (file["file_type"].ToString() != "FOLDER")
                {
                    newnode.SelectedImageIndex = 2;
                    newnode.ImageIndex         = 2;
                }
                else
                {
                    newnode.Nodes.Add("Loading...");
                }
            }
        }