|
@@ -1,6 +1,7 @@
|
|
|
using Google.Apis.Auth.OAuth2;
|
|
|
using Google.Apis.Download;
|
|
|
using Google.Apis.Drive.v3;
|
|
|
+using Google.Apis.Drive.v3.Data;
|
|
|
using Google.Apis.Services;
|
|
|
using Google.Apis.Util.Store;
|
|
|
using PDF_Office.Model.CloudDrive;
|
|
@@ -16,7 +17,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 对单账号处理的核心功能类
|
|
|
+ /// 单个用户
|
|
|
/// </summary>
|
|
|
public class GoogleDriveUserItem: UserBaseItem
|
|
|
{
|
|
@@ -46,7 +47,11 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
|
|
|
result = await CurrentCredential.RevokeTokenAsync(CancellationToken.None);
|
|
|
}
|
|
|
if (result == true)
|
|
|
+ {
|
|
|
CurrentCredential = null;
|
|
|
+ FilesList.Clear();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
return result;
|
|
|
}
|
|
@@ -55,25 +60,28 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
|
|
|
/// 获取帐号
|
|
|
/// </summary>
|
|
|
/// <returns>返回用户帐号地址</returns>
|
|
|
- private async Task<string> GetUserAcount()
|
|
|
+ private async Task<UserInfo> GetUserAcount()
|
|
|
{
|
|
|
- string userAcount = "";
|
|
|
+ UserInfo userInfo = null;
|
|
|
if (Service != null)
|
|
|
{
|
|
|
+ userInfo = new UserInfo();
|
|
|
var about = Service.About.Get();
|
|
|
about.Fields = "user";
|
|
|
- var uss = about.Execute().User;
|
|
|
- userAcount = uss.EmailAddress;
|
|
|
+ var uss = await about.ExecuteAsync();
|
|
|
+ User user = uss.User;
|
|
|
+ userInfo.UserAccount = user.EmailAddress;
|
|
|
+ userInfo.Name = user.DisplayName;
|
|
|
}
|
|
|
|
|
|
- return userAcount;
|
|
|
+ return userInfo;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取帐号
|
|
|
/// </summary>
|
|
|
/// <returns>返回用户帐号地址</returns>
|
|
|
- public async Task<string> GetUserAcountAsync()
|
|
|
+ public async Task<UserInfo> GetUserAcountAsync()
|
|
|
{
|
|
|
return await GetUserAcount();
|
|
|
}
|
|
@@ -238,7 +246,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
|
|
|
{
|
|
|
public static string[] Scopes = { DriveService.Scope.Drive };
|
|
|
//Google Drive应用名称
|
|
|
- private static readonly string GoogleDriveAppName = "PDF Office848";
|
|
|
+ private static readonly string GoogleDriveAppName = "PDF Office";
|
|
|
//请求应用进行身份验证的信息
|
|
|
public static string CredentialsPath { get; private set; }
|
|
|
|
|
@@ -276,25 +284,33 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
|
|
|
FilePath = System.IO.Path.Combine(FilesPathTemp, time + ".json");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- using (var stream = new FileStream(CredentialsPath, FileMode.Open, FileAccess.Read))
|
|
|
+ try
|
|
|
{
|
|
|
- credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
|
|
|
- GoogleClientSecrets.Load(stream).Secrets,
|
|
|
- Scopes,
|
|
|
- "user",
|
|
|
- CancellationToken.None,
|
|
|
- new FileDataStore(FilePath, true)).Result;
|
|
|
- }
|
|
|
+ using (var stream = new FileStream(CredentialsPath, FileMode.Open, FileAccess.Read))
|
|
|
+ {
|
|
|
+ credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
|
|
|
+ GoogleClientSecrets.Load(stream).Secrets,
|
|
|
+ Scopes,
|
|
|
+ "user",
|
|
|
+ CancellationToken.None,
|
|
|
+ new FileDataStore(FilePath, true)).Result;
|
|
|
+ }
|
|
|
|
|
|
- //create Drive API service.
|
|
|
- DriveService service = new DriveService(new BaseClientService.Initializer()
|
|
|
- {
|
|
|
- HttpClientInitializer = credential,
|
|
|
- ApplicationName = GoogleDriveAppName
|
|
|
- });
|
|
|
+ //create Drive API service.
|
|
|
+ DriveService service = new DriveService(new BaseClientService.Initializer()
|
|
|
+ {
|
|
|
+ HttpClientInitializer = credential,
|
|
|
+ ApplicationName = GoogleDriveAppName
|
|
|
+ });
|
|
|
|
|
|
- return tuple = new Tuple<DriveService, UserCredential>(service, credential);
|
|
|
+ return tuple = new Tuple<DriveService, UserCredential>(service, credential);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ //网络连接失败的情况
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -338,6 +354,21 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
|
|
|
return FolderPath;
|
|
|
}
|
|
|
|
|
|
+ public static bool ClearFilesPathTemp()
|
|
|
+ {
|
|
|
+ bool result = false;
|
|
|
+ string str_1 = System.AppDomain.CurrentDomain.BaseDirectory;
|
|
|
+ String FolderPath = str_1 + "GoogleDriveUsers";
|
|
|
+
|
|
|
+ if (Directory.Exists(FolderPath) == false)
|
|
|
+ {
|
|
|
+ Directory.Delete(FolderPath);
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 获取本地身份验证文件
|
|
|
/// </summary>
|