public Sync(string localFolder, string metadataFile, Mega api, string remoteFolderName) { this.metadataFile = metadataFile; this.localFolder = localFolder; remoteFolder = remoteFolderName; this.api = api; InitTimer(); InitWatcher(localFolder); }
private static IMegaRequest ThreadInit(MegaUser user, Action <Mega> OnSuccess, Action <int> OnError) { var initTransport = new Transport(); var mega = new Mega(initTransport); // mandatory anonymous registration if (user == null || (user.Email == null && user.Id == null)) { user = new MegaUser(); var req = new MRequestCreateAnon <MResponseCreateAnon>(user); int?error = null; req.Success += (s, args) => user.Id = args.UserId; req.Error += (s, e) => error = e.Error; initTransport.EnqueueRequest(req); req.ResetEvent.WaitOne(); if (error != null) { OnError((int)error); // just to have the ResetEvent for async compatibility return(new EmptyRequest()); } } // set the credentials mega.User = user; // the login itself var sidRequest = new MRequestGetSid <MResponseGetSid>(mega.User); sidRequest.Success += (s, args) => { mega.User.Sid = args.SessionId; mega.User.SetMasterKey(args.MasterKey.Value); var getUserRequest = new MRequestGetUser <MResponseGetUser>(mega.User); getUserRequest.Success += (s2, args2) => { mega.User.Status = args2.UserStatus; mega.User.Email = args2.Email; mega.User.Id = args2.UserId; OnSuccess(mega); }; getUserRequest.Error += (s2, e) => { OnError(e.Error); sidRequest.ResetEvent.Set(); }; initTransport.EnqueueRequest(getUserRequest); getUserRequest.ResetEvent.WaitOne(); }; sidRequest.Error += (s, a) => OnError(a.Error); initTransport.EnqueueRequest(sidRequest); return(sidRequest); }
private static IMegaRequest ThreadInit(MegaUser user, Action<Mega> OnSuccess, Action<int> OnError) { var initTransport = new Transport(); var mega = new Mega(initTransport); // mandatory anonymous registration if (user == null || (user.Email == null && user.Id == null)) { user = new MegaUser(); var req = new MRequestCreateAnon<MResponseCreateAnon>(user); int? error = null; req.Success += (s, args) => user.Id = args.UserId; req.Error += (s, e) => error = e.Error; initTransport.EnqueueRequest(req); req.ResetEvent.WaitOne(); if (error != null) { OnError((int)error); // just to have the ResetEvent for async compatibility return new EmptyRequest(); } } // set the credentials mega.User = user; // the login itself var sidRequest = new MRequestGetSid<MResponseGetSid>(mega.User); sidRequest.Success += (s, args) => { mega.User.Sid = args.SessionId; mega.User.SetMasterKey(args.MasterKey.Value); var getUserRequest = new MRequestGetUser<MResponseGetUser>(mega.User); getUserRequest.Success += (s2, args2) => { mega.User.Status = args2.UserStatus; mega.User.Email = args2.Email; mega.User.Id = args2.UserId; OnSuccess(mega); }; getUserRequest.Error += (s2, e) => { OnError(e.Error); sidRequest.ResetEvent.Set(); }; initTransport.EnqueueRequest(getUserRequest); getUserRequest.ResetEvent.WaitOne(); }; sidRequest.Error += (s, a) => OnError(a.Error); initTransport.EnqueueRequest(sidRequest); return sidRequest; }
public Sync(string localFolder, Mega api, string remoteFolderName) { this.localFolder = localFolder; var metadataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MegaDesktop"); Directory.CreateDirectory(metadataFolder); metadataFile = Path.Combine(metadataFolder, "files.metadata"); remoteStore = new NodeStore(api, "sync"); InitTimer(); InitWatcher(localFolder); }
public Mega InitSync(MegaUser user) { Mega api = null; int? error = null; ThreadInit(user, (m) => api = m, (i) => error = i).ResetEvent.WaitOne(); if (api == null || error != null) { throw new MegaApiException((int)error, "Login error"); } return(api); }
public NodeStore(Mega api, string rootFolderName) { RecycleDeletedItems = true; this.api = api; api.ServerRequest += HandleServerRequest; this.rootFolderName = rootFolderName; refreshTimer = new Timer { Interval = 15*60*1000, AutoReset = false, Enabled = false }; refreshTimer.Elapsed += (s, e) => RefreshNodeList(); RefreshNodeList(); }
public MegaProvider(Mega api, string syncFolderName) { this.api = new MegaStore(api, syncFolderName); this.api.ProgressChanged += (s, e) => OnProgressChanged(); _replicaMetadataFile = MetadataDirectory + _name + ".Metadata"; _replicaIdFile = MetadataDirectory + _name + ".Replicaid"; _idFormats = new SyncIdFormatGroup(); _idFormats.ChangeUnitIdFormat.IsVariableLength = false; _idFormats.ChangeUnitIdFormat.Length = 4; _idFormats.ItemIdFormat.IsVariableLength = false; _idFormats.ItemIdFormat.Length = 24; _idFormats.ReplicaIdFormat.IsVariableLength = false; _idFormats.ReplicaIdFormat.Length = 16; this.ItemConstraint += new EventHandler<SimpleSyncItemConstraintEventArgs>(OnItemConstraint); this.ItemConflicting += new EventHandler<SimpleSyncItemConflictingEventArgs>(OnItemConflicting); }
private void buttonLogin_Click(object sender, RoutedEventArgs e) { var w = new WindowLogin(); w.OnLoggedIn += (s, args) => { api = args.Api; SaveAccount(GetUserKeyFilePath(), "user.anon.dat"); Invoke(() => { CancelTransfers(); w.Close(); buttonLogin.Visibility = System.Windows.Visibility.Collapsed; buttonLogout.Visibility = System.Windows.Visibility.Visible; Title = title + " - " + api.User.Email; }); InitialLoadNodes(); }; w.ShowDialog(); }
private MegaUser Login(bool save, string userAccountFile) { MegaUser u; if ((u = Mega.LoadAccount(userAccountFile)) == null) { save = true; } SetStatus("Logging in..."); Mega.Init(u, (m) => { api = m; if (save) { SaveAccount(userAccountFile, "user.anon.dat"); } InitializeComponent(); InitialLoadNodes(); SetStatusDone(); if (api.User.Status == MegaUserStatus.Anonymous) { Invoke(() => { buttonLogin.Visibility = System.Windows.Visibility.Visible; buttonLogout.Visibility = System.Windows.Visibility.Collapsed; Title = title + " - anonymous account"; }); } else { Invoke(() => { Title = title + " - " + m.User.Email; buttonLogin.Visibility = System.Windows.Visibility.Collapsed; buttonLogout.Visibility = System.Windows.Visibility.Visible; }); } }, (e) => { MessageBox.Show("Error while loading account: " + e); Application.Current.Shutdown(); }); return u; }
public MegaStore(Mega api, string rootFolderName) { this.api = api; this.rootFolderName = rootFolderName; }
static void Main(string[] args) { SaveDirectory = args[0]; ScheduleURL = args[1]; CompressSeries = args[2] == "compressseries"; ConsoleExt.Start(); HTMLRender.Initialize(); var downloaded = File.ReadAllLines("downloaded.txt"); Mega = new Mega(); foreach (var line in downloaded) { MatchList.Add(int.Parse(line)); DemoList.Add(int.Parse(line), null); } ConsoleExt.Log("Starting."); if (CompressSeries) { var account = File.ReadAllLines("megaaccount.txt"); ConsoleExt.Log("Logging into Mega."); Mega2.Init(new MegaUser(account[0], account[1]), (a => { ConsoleExt.Log("Logged into Mega."); Mega2 = a; Mega.sid2 = a.User.Sid; }), (a => { ConsoleExt.Log( "Failed to log into Mega. Error code: {0}", a); Mega2 = null; })); } if (!File.Exists("matchiddownload.txt")) { ConsoleExt.Log("Starting spider on {0}.", ScheduleURL); CheckLoop(); } else { ConsoleExt.Log("Found matchiddownload.txt, forcing regular downloads."); var data = File.ReadAllLines("matchiddownload.txt"); var first = true; var series = ""; foreach (string t in data) { if (first) { series = t; first = false; } else if (string.IsNullOrWhiteSpace(t)) { first = true; } else { if (!MatchIDList.ContainsKey(series)) { MatchIDList.Add(series, new List <string>()); } MatchIDList[series].Add(t); } } foreach (var pair in MatchIDList) { for (int i = 0; i < pair.Value.Count; i++) { var game = pair.Value[i]; DownloadDemoId(game, pair.Key, ((i + 1) == pair.Value.Count)); } } } ConsoleExt.Log("Done."); Console.Read(); }
private void StartSync(Mega m) { api = m; m.SaveAccount(GetUserKeyFilePath()); Invoke(new Action(() => { buttonExit.Enabled = true; WindowState = FormWindowState.Minimized; })); Log("Working..."); var sync = new Sync(Properties.Settings.Default.folderPath, GetMetadataPath(), api, "sync"); sync.ChangePerformed += (s, e) => { Log("{0} [{1}]: {2}", e.IsLocal ? "local" : "remote", e.Time.ToShortTimeString(), e.Message); }; sync.SyncError += (s, e) => { Log("Synchronization error: {1} \r\n{0}", e.Exception, e.Message); Invoke(new Action(() => { notifyIcon1.ShowBalloonTip(60000, "Synchronization Error", e.Message + "\r\n" + e.Exception.Message, ToolTipIcon.Error); })); GoogleAnalytics.SendTrackingRequest("/SyncError"); }; sync.SyncEnded += (s, e) => { Log("Sync ended at {0}", DateTime.Now.ToShortTimeString()); }; sync.SyncStarted += (s, e) => { Log("Sync started at {0}", DateTime.Now.ToShortTimeString()); }; sync.StartSyncing(); }