|
@@ -1,6 +1,8 @@
|
|
using Dropbox.Api;
|
|
using Dropbox.Api;
|
|
|
|
+using Dropbox.Api.Files;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
+using System.IO;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Text;
|
|
@@ -28,7 +30,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
|
|
private string currentFolder = "";
|
|
private string currentFolder = "";
|
|
|
|
|
|
HttpListener http = new HttpListener();
|
|
HttpListener http = new HttpListener();
|
|
- private async void btnConnect_Click()
|
|
|
|
|
|
+ private async void Connect()
|
|
{
|
|
{
|
|
DropboxCertHelper.InitializeCertPinning();
|
|
DropboxCertHelper.InitializeCertPinning();
|
|
var state = Guid.NewGuid().ToString("N");
|
|
var state = Guid.NewGuid().ToString("N");
|
|
@@ -37,16 +39,9 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
|
|
//var http = new HttpListener();
|
|
//var http = new HttpListener();
|
|
http.Prefixes.Clear();
|
|
http.Prefixes.Clear();
|
|
http.Prefixes.Add(LoopbackHost);
|
|
http.Prefixes.Add(LoopbackHost);
|
|
-
|
|
|
|
-
|
|
|
|
http.Start();
|
|
http.Start();
|
|
-
|
|
|
|
- // IAsyncResult result = http.BeginGetContext(new AsyncCallback(ListenerCallback), http);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
System.Diagnostics.Process.Start(authorizeUri.ToString());
|
|
System.Diagnostics.Process.Start(authorizeUri.ToString());
|
|
|
|
|
|
-
|
|
|
|
await HandleOAuth2Redirect(http);
|
|
await HandleOAuth2Redirect(http);
|
|
|
|
|
|
// Handle redirect from JS and process OAuth response.
|
|
// Handle redirect from JS and process OAuth response.
|
|
@@ -63,8 +58,6 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
public static void ListenerCallback(IAsyncResult result)
|
|
public static void ListenerCallback(IAsyncResult result)
|
|
{
|
|
{
|
|
HttpListener listener = (HttpListener)result.AsyncState;
|
|
HttpListener listener = (HttpListener)result.AsyncState;
|
|
@@ -145,5 +138,96 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ private void Download()
|
|
|
|
+ {
|
|
|
|
+ //if (ItemList.SelectedItem != null)
|
|
|
|
+ //{
|
|
|
|
+ // var item = ItemList.SelectedItem as Metadata;
|
|
|
|
+ // if (item.IsFolder)
|
|
|
|
+ // return;
|
|
|
|
+
|
|
|
|
+ // SaveFileDialog saveFileDialog = new SaveFileDialog();
|
|
|
|
+ // saveFileDialog.FileName = item.Name;
|
|
|
|
+ // if ((bool)saveFileDialog.ShowDialog())
|
|
|
|
+ // {
|
|
|
|
+ // string folder = item.PathDisplay.Replace("/" + item.Name, "");
|
|
|
|
+ // using (var response = await client.Files.DownloadAsync(item.PathDisplay))
|
|
|
|
+ // {
|
|
|
|
+ // var result = await response.GetContentAsStreamAsync();
|
|
|
|
+ // var stream = StreamToMemoryStream(result);
|
|
|
|
+ // using (var fileStream = System.IO.File.Create(saveFileDialog.FileName))
|
|
|
|
+ // {
|
|
|
|
+ // stream.Seek(0, System.IO.SeekOrigin.Begin);
|
|
|
|
+ // stream.CopyTo(fileStream);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // MessageBox.Show("下载完成");
|
|
|
|
+ // System.Diagnostics.Process.Start(@"explorer.exe", "/select,\"" + saveFileDialog.FileName + "\"");
|
|
|
|
+ // RefreshList(folder);
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public MemoryStream StreamToMemoryStream(Stream stream)
|
|
|
|
+ {
|
|
|
|
+ MemoryStream memoryStream = new MemoryStream();
|
|
|
|
+
|
|
|
|
+ //将基础流写入内存流
|
|
|
|
+ const int bufferLength = 1024;
|
|
|
|
+ byte[] buffer = new byte[bufferLength];
|
|
|
|
+ int actual = stream.Read(buffer, 0, bufferLength);
|
|
|
|
+ while (actual > 0)
|
|
|
|
+ {
|
|
|
|
+ // 读、写过程中,流的位置会自动走。
|
|
|
|
+ memoryStream.Write(buffer, 0, actual);
|
|
|
|
+ actual = stream.Read(buffer, 0, bufferLength);
|
|
|
|
+ }
|
|
|
|
+ memoryStream.Position = 0;
|
|
|
|
+
|
|
|
|
+ return memoryStream;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void Upload()
|
|
|
|
+ {
|
|
|
|
+ //if (ItemList.SelectedItem != null)
|
|
|
|
+ //{
|
|
|
|
+ // var item = ItemList.SelectedItem as Metadata;
|
|
|
|
+ // if (item.IsFolder)
|
|
|
|
+ // return;
|
|
|
|
+
|
|
|
|
+ //OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
|
+ //if ((bool)openFileDialog.ShowDialog())
|
|
|
|
+ //{
|
|
|
|
+ // string folder = currentFolder; /*= item.PathDisplay.Replace("/" + item.Name, "");*/
|
|
|
|
+ // using (var stream = System.IO.File.OpenRead(openFileDialog.FileName))
|
|
|
|
+ // {
|
|
|
|
+ // await client.Files.UploadAsync(folder + "/" + openFileDialog.SafeFileName, WriteMode.Overwrite.Instance, body: stream);
|
|
|
|
+ // }
|
|
|
|
+ // MessageBox.Show("上传完成");
|
|
|
|
+ // RefreshList(folder);
|
|
|
|
+ //}
|
|
|
|
+ //}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void Loaded()
|
|
|
|
+ {
|
|
|
|
+ //var text = sender as TextBlock;
|
|
|
|
+ //if (text == null)
|
|
|
|
+ // return;
|
|
|
|
+ //if (text.DataContext is Metadata)
|
|
|
|
+ //{
|
|
|
|
+ // var data = (text.DataContext as Metadata);
|
|
|
|
+ // if (data.IsFile)
|
|
|
|
+ // {
|
|
|
|
+ // text.Text = "File";
|
|
|
|
+ // }
|
|
|
|
+ // if (data.IsFolder)
|
|
|
|
+ // {
|
|
|
|
+ // text.Text = "Folder";
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|