示例#1
0
        public async Task <bool> PrepareAsync(CookieAwareWebClient client, CancellationToken cancellation)
        {
            _client = new MegaApiClient(new Options(InternalUtils.GetMegaAppKey().Item1));

            var storage = SettingsHolder.Content.MegaAuthenticationStorage;
            var token   = new MegaApiClient.LogonSessionToken(
                storage.GetEncrypted <string>(KeySession),
                storage.GetEncrypted <byte[]>(KeyToken));

            if (!string.IsNullOrWhiteSpace(token.SessionId) && token.MasterKey != null)
            {
                await _client.LoginAsync(token);
            }
            else
            {
                await _client.LoginAnonymousAsync();
            }

            try {
                var information = await _client.GetNodeFromLinkAsync(_uri);

                TotalSize = information.Size;
                FileName  = information.Name;
                return(true);
            } catch (ApiException e) {
                WindowsHelper.ViewInBrowser(_uri);
                throw new InformativeException("Unsupported link", "Please download it manually.", e);
            }
        }
示例#2
0
        public static async Task <MegaApiClient> LoginAsync(string account, string code, string settingsPassPhrase)
        {
            if (string.IsNullOrEmpty(account))
            {
                throw new ArgumentNullException(nameof(account));
            }

            var client = new MegaApiClient();

            var refreshToken = LoadRefreshToken(account, settingsPassPhrase);

            if (refreshToken != null)
            {
                await client.LoginAsync(refreshToken);
            }
            else
            {
                if (string.IsNullOrEmpty(code))
                {
                    code = GetAuthCode(account);
                }

                var parts = code?.Split(new[] { ',' }, 2) ?? Array.Empty <string>();
                if (parts.Length != 2)
                {
                    throw new AuthenticationException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.ProvideAuthenticationData, account));
                }

                refreshToken = MegaApiClient.GenerateAuthInfos(parts[0], parts[1]);
                client.Login(refreshToken);
            }

            SaveRefreshToken(account, refreshToken, settingsPassPhrase);

            return(client);
        }
示例#3
0
        public async Task <bool> PrepareAsync(CookieAwareWebClient client, CancellationToken cancellation)
        {
            _client = new MegaApiClient(new Options(InternalUtils.GetMegaAppKey().Item1));

            var storage = SettingsHolder.Content.MegaAuthenticationStorage;
            var token   = new MegaApiClient.LogonSessionToken(
                storage.GetEncrypted <string>(KeySession),
                storage.GetEncrypted <byte[]>(KeyToken));

            if (!string.IsNullOrWhiteSpace(token.SessionId) && token.MasterKey != null)
            {
                await _client.LoginAsync(token);
            }
            else
            {
                await _client.LoginAnonymousAsync();
            }

            var information = await _client.GetNodeFromLinkAsync(_uri);

            TotalSize = information.Size;
            FileName  = information.Name;
            return(true);
        }