//Delete Button private void tsDelete_Click(object sender, EventArgs e) { //Delete from DropBox if (MessageBox.Show("Delete this File?", "SoulSave", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DropboxClient _client = new DropboxClient(SoulDB.GetAccessTokenFromFile()); //Generate Path string __itemName = txtListItem.Text; string _folderName = __itemName.Split('_')[0]; string _path = "/" + _folderName + "/" + __itemName; //Timestamp from file string _timestamp = Path.GetFileNameWithoutExtension(__itemName.Substring(__itemName.LastIndexOf('_') + 1)); if (SoulDB.Delete(_path, _client)) { //Delete the hash of the file if (RemoveFromHashText("hash.text", _timestamp)) { MessageBox.Show("Delete Successful", "Soul Save", MessageBoxButtons.OK, MessageBoxIcon.Information); RefreshList(); } } else { MessageBox.Show("Cannot Delete File", "Soul Save", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
//Create Default Folders on DropBox public void CreateDefaultFolders() { //If already Logged In if (SoulDB.isLoggedInDataAvaiable()) { _client = new DropboxClient(SoulDB.GetAccessTokenFromFile()); if (SoulDB.isFolderExist("/DarkSouls", _client) == false) { SoulDB.CreateFolder("/DarkSouls", _client); } if (SoulDB.isFolderExist("/DarkSoulsII", _client) == false) { SoulDB.CreateFolder("/DarkSoulsII", _client); } if (SoulDB.isFolderExist("/DarkSoulsIII", _client) == false) { SoulDB.CreateFolder("/DarkSoulsIII", _client); } if (SoulDB.isFolderExist("/Sekiro", _client) == false) { SoulDB.CreateFolder("/Sekiro", _client); } } else { //not Logged in if (SoulDB.isFolderExist("/Darksouls", baseDropBox._client) == false) { SoulDB.CreateFolder("/Darksouls", baseDropBox._client); } if (SoulDB.isFolderExist("/DarkSoulsII", _client) == false) { SoulDB.CreateFolder("/DarkSoulsII", _client); } if (SoulDB.isFolderExist("/DarkSoulsIII", _client) == false) { SoulDB.CreateFolder("/DarkSoulsIII", _client); } if (SoulDB.isFolderExist("/Sekiro", _client) == false) { SoulDB.CreateFolder("/Sekiro", _client); } } }
//Load the LoadingDownload Form private void ProgressBarLoad(object sender, EventArgs e) { //Generate Path string __itemName = txtListItem.Text; string _folderName = __itemName.Split('_')[0]; string _path = "/" + _folderName; //Reference to the Downloaded File downloadedFile = Utilities.getApplicationPath() + @"\" + "Download" + @"\" + __itemName; DropboxClient client = new DropboxClient(SoulDB.GetAccessTokenFromFile()); Task task = Task.Run(() => Download(_client, _path, __itemName, downloadedFile)).ContinueWith(t => isDoneValidating = validateHash(downloadedFile, __itemName)); }
//Dropbox Get All Folder/Files public async Task Run() { //Get all files and folders from dropbox //bool isNoFile = false; File.Delete(list); using (var _c = new DropboxClient(SoulDB.GetAccessTokenFromFile())) { var listOfFoldrs = await _c.Files.ListFolderAsync(string.Empty, true); //get the number of folders on dropbox int x = listOfFoldrs.Entries.Count; //4 is the number of folder generated by the app //Darksouls, DarkSoulsII, DarkSOulsIII, Sekiro if (x > 4) { FolderMetadata FolderInfo = new FolderMetadata(); FileMetadata FileInfo = new FileMetadata(); foreach (var item in listOfFoldrs.Entries) { try { if (item.IsFile) { FileInfo = (FileMetadata)item; File.WriteToTextFile(FileInfo.PathDisplay.ToString(), list); } } catch (Exception ex) { throw; } } } else { MessageBox.Show("There were no files", "Soul Save", MessageBoxButtons.OK, MessageBoxIcon.Information);; } } }
//Upload to dropBox public static bool UploadToDropbox(string UploadFolder, string Filename, string Source) { try { DropboxClient _c = new DropboxClient(SoulDB.GetAccessTokenFromFile()); if (SoulDB.isLoggedInDataAvaiable()) { if (SoulDB.UploadFile(UploadFolder, Filename, Source, _c)) { bStatus = true; } else { //Delete All files on Temp Folder DirectoryInfo directoryInfo = new DirectoryInfo(Utilities.getApplicationPath() + @"\" + _dir); foreach (FileInfo file in directoryInfo.EnumerateFiles()) { file.Delete(); } bStatus = false; } } if (bStatus) { return(true); } else { return(false); } } catch (Exception) { return(false); } }