private void ApplicationBarMenuItem_Click_2(object sender, EventArgs e) { // Download the zip // Connect to live API LiveAuthClient auth = new LiveAuthClient("00000000440E7119"); auth.InitializeAsync(); auth.InitializeCompleted += (e1, e2) => { // Show login dialog auth.LoginAsync(new string[] { "wl.skydrive_update", "wl.skydrive" }); auth.LoginCompleted += (e3, e4) => { if (e4.Status == LiveConnectSessionStatus.Connected) { LiveConnectClient client = new LiveConnectClient(e4.Session); // Upload that zip we just made client.GetAsync("me/skydrive/files"); client.GetCompleted += (getSender, getEvents) => { Dictionary <string, object> fileData = (Dictionary <string, object>)getEvents.Result; List <object> files = (List <object>)fileData["data"]; foreach (object item in files) { Dictionary <string, object> file = (Dictionary <string, object>)item; if (file["name"].ToString() == "wphfolders.zip") { System.Diagnostics.Debug.WriteLine(file["name"]); client.DownloadAsync(file["id"].ToString() + "/content"); client.DownloadCompleted += (downloadSender, downloadEventArgs) => { SharpGIS.UnZipper unzipper = new SharpGIS.UnZipper(downloadEventArgs.Result); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { foreach (string name in unzipper.FileNamesInZip) { var storefile = store.OpenFile(name, FileMode.Create, FileAccess.Write); unzipper.GetFileStream(name).CopyTo(storefile); storefile.Close(); } } MessageBox.Show("Restored."); regenerateList(); }; } } }; } else { MessageBox.Show("Not connected to SkyDrive"); } }; }; }
void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { Microsoft.Phone.Shell.SystemTray.SetProgressIndicator(this, new Microsoft.Phone.Shell.ProgressIndicator() { IsIndeterminate = true, IsVisible = false }); if (e.Error == null) { using (var stor = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication()) { SharpGIS.UnZipper u = new SharpGIS.UnZipper(e.Result); stor.CreateDirectory((string)e.UserState); foreach (string file in u.FileNamesInZip) { System.Diagnostics.Debug.WriteLine(file); if (file.Contains("/")) { string dir = e.UserState + "/" + file.Substring(0, file.IndexOf("/")); if (!stor.DirectoryExists(dir)) { stor.CreateDirectory(dir); } } using (var str = stor.CreateFile(e.UserState + "\\" + file)) { u.GetFileStream(file).CopyTo(str); } } } } this.Dispatcher.BeginInvoke(() => { MessageBox.Show("Theme installed: " + e.UserState, "Success!", MessageBoxButton.OK); updateThemes(); }); }