internal void Consider(DictBundle b) { List <string> strings = new List <string>(); if (b.path != "_gameaid/_savedRolls") { return; } selList.Items.Clear(); foreach (var k in b.dict) { if (k.Value == "<Folder>" && k.Key != "..") { strings.Add(k.Key); } } // contents now loaded, sort them up strings.Sort(StringComparer.InvariantCultureIgnoreCase); foreach (var k in strings) { selList.Items.Add(k); } // we're done with our one item access, clear this to prevent further considers Main.openSaveRollsDlg = null; }
internal void Consider(DictBundle b) { m_results.Items.Clear(); if (!_fFiles) { return; } if (b.path != "download-result") { return; } if (b.dict == null || !b.dict.ContainsKey("folder")) { return; } if (b.dict["folder"] != "gameaid") { return; } _fileList.Clear(); for (int i = 0; i < b.dict.Count; i++) { string key = i.ToString(); if (b.dict.ContainsKey(key)) { _fileList.Add(b.dict[key]); } } _fileList.Sort(StringComparer.InvariantCultureIgnoreCase); foreach (var val in _fileList) { var url = Config.uploads_gameaid + val; AddImage(val, url); } }
public void Consider(DictBundle b) { if (b.dict == null) { return; } if (b.path == "_gameaid/_remote") { string srKey = Main.mychannel + "|sr"; string roundKey = Main.mychannel + "|round"; int sr = 0; if (b.dict.ContainsKey(srKey) && Int32.TryParse(b.dict[srKey], out sr)) { srLast = sr; RunPendingRolls(); } string round = ""; if (b.dict.ContainsKey(roundKey)) { round = b.dict[roundKey]; if (round != roundLast) { roundLast = round; ResetRollButtons(); } } if (Main.gm_mode) { return; } string locKey = Main.mychannel + "|loc"; if (!b.dict.ContainsKey(locKey) || b.dict[locKey] == "") { return; } var newLoc = b.dict[locKey].ToLower(); if (newLoc == defaultLoc) { return; } defaultLoc = newLoc; string regLoc, missileLoc; if (defaultLoc.Contains("_missile")) { regLoc = defaultLoc.Replace("_missile", ""); missileLoc = defaultLoc; } else { regLoc = defaultLoc; missileLoc = defaultLoc + "_missile"; } SetComboToValue(locCombo, regLoc); foreach (var ch in mainGrid.Children) { var cb = ch as ComboBox; if (cb == null) { continue; } SetComboDefaultLoc(cb); } } }
void OfferDownloads(DictBundle b) { // gameaid folder is for images not spreadsheets if (b.dict.ContainsKey("folder") && b.dict["folder"] == "gameaid") { return; } // clear the download menu and put the default enter pin item back ResetDownloadMenu(); var items = new Dictionary <string, MenuItem>(); for (int i = 0; i < b.dict.Count; i++) { var k = i.ToString(); if (b.dict.ContainsKey(k)) { var filename = b.dict[k]; // map the file name to the character group like "Halakiv" or whatever string group; if (!filenameDict.TryGetValue(filename, out group)) { group = "Ungrouped"; } MenuItem parent; MenuItem m; TextBlock t; // create a new group if needed and add them to the menu as they occur if (!items.ContainsKey(group)) { m = new MenuItem(); t = new TextBlock(); t.Text = group; m.Header = t; items[group] = m; parent = m; } else { parent = items[group]; } // now add the actual file download open to the appropriate group menu item m = new MenuItem(); t = new TextBlock(); t.Text = filename; m.Header = t; m.Click += new RoutedEventHandler(FileDownload_Click); parent.Items.Add(m); } } // now finally, order group the items so we can add them to the download menu var q = from p in items.Keys orderby p select items[p]; foreach (MenuItem m in q) { download_menu.Items.Add(m); } }
public void OnHostEvent(object sender, ProgressChangedEventArgs e) { if (e.UserState is Exception) { Exception ex = e.UserState as Exception; PopupString(ex.ToString() + "\r\n" + ex.StackTrace.ToString()); } if (e.UserState is string) { /* * string line = (string)e.UserState; * * textHistory.AppendText(line + "\r\n"); * textHistory.ScrollToEnd(); */ } else if (e.UserState is EvalBundle) { EvalBundle b = (EvalBundle)e.UserState; ProcessEvals(b); } else if (e.UserState is DictBundle) { DictBundle b = (DictBundle)e.UserState; if (b.path == "download-result") { OfferDownloads(b); if (accessLibraryDlg != null) { accessLibraryDlg.Consider(b); } } else { if (b.path == "_gameaid/_filenames") { filenameDict = b.dict; } partyInfo1.Consider(b); partyInfo2.Consider(b); vs1.Consider(b); readyRolls.Consider(b); if (openSaveRollsDlg != null) { openSaveRollsDlg.Consider(b); } map1.Consider(b); map2.Consider(b); foreach (var sq in Squad.Children) { var sheet = sq as VirtualSheet; if (sheet != null) { sheet.Consider(b); } } } } else if (e.UserState is DownloadFile) { DownloadFile file = e.UserState as DownloadFile; // Configure open file dialog box var dlg = new System.Windows.Forms.SaveFileDialog(); dlg.Title = "Save Download"; dlg.FileName = file.name; dlg.DefaultExt = ".xlsx"; // Default file extension dlg.Filter = "Character Sheets (.xlsx)|*.xlsx"; // Filter files by extension dlg.OverwritePrompt = true; dlg.CheckPathExists = true; // Show open file dialog box System.Windows.Forms.DialogResult result = dlg.ShowDialog(); // Process open file dialog box results if (result == System.Windows.Forms.DialogResult.OK) { try { System.IO.File.WriteAllBytes(dlg.FileName, file.bytes); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); return; } } } else if (e.UserState is AudioReport) { AudioReport audio = e.UserState as AudioReport; string url = ""; switch (audio.desc) { case "speak": if (reader == null) { try { // tolerate reader acquisition failure more gracefully reader = new SpeechSynthesizer(); // var l = new List<VoiceInfo>(); // // foreach (InstalledVoice voice in reader.GetInstalledVoices()) // { // VoiceInfo info = voice.VoiceInfo; // string AudioFormats = ""; // foreach (SpeechAudioFormatInfo fmt in info.SupportedAudioFormats) // { // AudioFormats += String.Format("{0}\n", // fmt.EncodingFormat.ToString()); // } // // l.Add(info); // // } reader.SelectVoice("Microsoft Zira Desktop"); } catch { } } if (reader != null) { reader.SpeakAsync(audio.text); } break; case "ownage": switch (audio.killcount) { case 1: url = "http://myserver.com/uploads/killshot/1.mp3"; break; case 2: url = "http://myserver.com/uploads/killshot/4.mp3"; break; case 3: url = "http://myserver.com/uploads/killshot/6.mp3"; break; case 4: url = "http://myserver.com/uploads/killshot/7.mp3"; break; case 5: url = "http://myserver.com/uploads/killshot/10.mp3"; break; case 6: url = "http://myserver.com/uploads/killshot/9.mp3"; break; case 7: default: url = "http://myserver.com/uploads/killshot/14.mp3"; break; } break; case "fumble": url = "http://myserver.com/uploads/killshot/0.mp3"; break; default: url = "http://myserver.com/uploads/misc/" + audio.desc; break; } if (url != "") { var player = new System.Windows.Media.MediaPlayer(); player.Open(new Uri(url)); player.MediaOpened += new EventHandler((object s, EventArgs a) => { player.Play(); }); player.MediaEnded += new EventHandler((object s, EventArgs a) => { player.Close(); }); } } else if (e.UserState is HoursReport) { HoursReport h = e.UserState as HoursReport; vs1.SetRemainingHours(h.hours); } }
public void HandleHost(object sender, DoWorkEventArgs e) { BackgroundWorker b = (BackgroundWorker)sender; DictBundle pending = null; string a1, a2, a3, a4; for (;;) { try { hostClient = new System.Net.Sockets.TcpClient(server, 6668); NetworkStream stream = hostClient.GetStream(); HybridStreamReader r = new HybridStreamReader(stream); HybridStreamReader savedStream = null; SendHost("nick " + nick); SendHost("dir /"); SendHost("dir _maps/default"); string line; for (; ;) { if ((line = r.ReadLine()) == null) { if (savedStream != null) { r = savedStream; savedStream = null; continue; } break; } if (line.StartsWith("hours ")) { int hours; Parse2(line, out a1, out a2); Int32.TryParse(a2, out hours); var h = new HoursReport(); h.hours = hours; b.ReportProgress(1, h); } else if (line.StartsWith("audio ")) { int count; Parse3(line, out a1, out a2, out a3); var audio = new AudioReport(); audio.desc = a2; if (a2 == "ownage") { Int32.TryParse(a3, out count); audio.killcount = count; } else { audio.text = a3; } b.ReportProgress(1, audio); } else if (line.StartsWith("download ")) { int len; Parse3(line, out a1, out a2, out a3); Int32.TryParse(a3, out len); var bytes = new byte[len]; r.Read(bytes); var download = new DownloadFile(); download.name = a2; download.bytes = bytes; b.ReportProgress(1, download); } else if (line.StartsWith("compressed ")) { int clen, len; Parse3(line, out a1, out a2, out a3); Int32.TryParse(a2, out clen); Int32.TryParse(a3, out len); // switch to the saved stream savedStream = r; r = UncompressBytes(r, clen); if (r == null) { r = savedStream; } continue; } else if (line.StartsWith("begin eval ")) { pending = new EvalBundle(); Parse3(line, out a1, out a2, out a3); pending.path = a3; } else if (line.StartsWith("begin dir ")) { pending = new DictBundle(); Parse3(line, out a1, out a2, out a3); pending.path = a3; } else if (pending != null && line.StartsWith("v ")) { Parse4(line, out a1, out a2, out a3, out a4); if (a1 != "v" || a2 != pending.path) { continue; } if (!pending.dict.ContainsKey(a3)) { pending.dict.Add(a3, a4); } } else if (line.StartsWith("end dir ")) { b.ReportProgress(1, pending); pending = null; } else if (line.StartsWith("end eval ")) { b.ReportProgress(1, pending); pending = null; } else if (pending == null) { b.ReportProgress(1, line); } } } catch (Exception ex) { b.ReportProgress(0, ex); System.Threading.Thread.Sleep(5000); } } }