/// <summary> /// Update with online settings. /// </summary> /// <param name="center">The ScoreCenter object.</param> /// <param name="force">True to force the online update.</param> /// <returns></returns> public static bool OnlineUpdate(ScoreCenter center, bool force) { bool result = false; if (center.Setup == null) { return(false); } Tools.LogMessage("Start Online Update"); Tools.LogMessage(" Mode: {0}", center.Setup.UpdateOnlineMode); Tools.LogMessage(" URL: {0}", center.Setup.UpdateUrl); Tools.LogMessage(" Options: {0}", center.Setup.UpdateRule); Tools.LogMessage(" Force: {0}", force); if (center.Setup.DoUpdate(force, center.Scores.Items == null ? 0 : center.Scores.Items.Length) && String.IsNullOrEmpty(center.Setup.UpdateUrl) == false) { ImportOptions options = (ImportOptions)Enum.Parse(typeof(ImportOptions), center.Setup.UpdateRule, true); result = OnlineUpdate(center, center.Setup.UpdateUrl, options); Tools.LogMessage("End Update: {0}", result); } else { Tools.LogMessage("End Update: Cancelled"); } return(result); }
public static void Export(ScoreCenter source, string fileName, List <BaseScore> scores) { // create a new object and add the exported scores ScoreCenter center = new ScoreCenter(); center.Scores = new ScoreCenterScores(); center.Scores.Items = new BaseScore[scores.Count]; scores.CopyTo(center.Scores.Items); // add the styles List <string> styles = new List <string>(); foreach (BaseScore score in scores) { styles.AddRange(score.GetStyles()); } var dstyles = styles.Distinct(); center.Styles = new Style[dstyles.Count()]; int i = 0; foreach (string str in dstyles) { center.Styles[i++] = source.FindStyle(str); } Tools.SaveSettings(fileName, center, false, false); }
private static void ImportParameters(ScoreCenter center, ScoreCenter imported) { if (imported == null || imported.Parameters == null) { return; } if (center.Parameters == null) { center.Parameters = imported.Parameters; } else { List <ScoreParameter> toAdd = new List <ScoreParameter>(); foreach (ScoreParameter ip in imported.Parameters) { if (center.Parameters.FirstOrDefault(p => p.name == ip.name) == null) { toAdd.Add(ip); } } if (toAdd.Count > 0) { center.Parameters = center.Parameters.Concat(toAdd).ToArray(); } } }
private void OnLiveSettingsCreated(object sender, FileSystemEventArgs e) { Tools.LogMessage("Start ScoreCenterLive"); System.Threading.Thread.Sleep(1000); ScoreCenter center = Tools.ReadSettings(m_liveSettings, false); if (center == null) { Tools.LogMessage("NO LIVE Settings: {0}", m_liveSettings); return; } center.Setup.CacheExpiration = 0; center.ReplaceVirtualScores(); var liveScores = center.Scores.Items; Tools.LogMessage("Live: nb scores = {0}", liveScores.Count()); if (liveScores.Count() == 0) { return; } m_liveCenter = new LiveCenter(liveScores, center); m_liveCenter.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(LiveCenterWorkerCompleted); m_liveCenter.RunWorkerAsync(); }
/// <summary> /// Constructor. /// </summary> /// <param name="file">The file to import.</param> /// <param name="center">The score center to import into.</param> public ImportDialog(string file, ScoreCenter center) { InitializeComponent(); m_center = center; m_fileName = file; }
protected override void OnPageDestroy(int new_windowId) { bgwTimer.CancelAsync(); ClearProperties(0); m_center = null; //ClearGrid(); base.OnPageDestroy(new_windowId); }
public void ReadSettings() { try { m_center = Tools.ReadSettings(m_settgins, false); } catch (Exception exc) { GUIControl.SetControlLabel(GetID, 20, exc.Message); } }
/// <summary> /// Import a list of scores in an existing center. /// </summary> /// <param name="center">The existing center.</param> /// <param name="imported">The center to import.</param> /// <param name="mergeOptions">The merge options.</param> /// <returns>The number of scores imported.</returns> public static int Import(ScoreCenter center, ScoreCenter imported, ImportOptions mergeOptions) { int result = 0; if (imported.Scores.Items == null) { return(result); } bool isnew = center.Scores.Items != null; List <BaseScore> toImport = new List <BaseScore>(); foreach (BaseScore score in imported.Scores.Items) { BaseScore exist = center.FindScore(score.Id); if (exist != null) { // merge (or not) bool merged = exist.Merge(score, mergeOptions); if (merged) { result++; } } else { // import new if ((mergeOptions & ImportOptions.New) == ImportOptions.New) { toImport.Add(score); result++; score.SetNew(isnew); score.enable = true; } } } if (toImport.Count > 0) { if (center.Scores.Items == null) { center.Scores.Items = toImport.ToArray(); } else { center.Scores.Items = center.Scores.Items.Concat(toImport).ToArray(); } } // import parameters ExchangeManager.ImportParameters(center, imported); return(result); }
public StyleDialog(ScoreCenter center) { InitializeComponent(); m_center = center; if (m_center.Setup != null) { pnlSkinColor.BackColor = Color.FromArgb(m_center.Setup.DefaultSkinColor); pnlFontColor.BackColor = Color.FromArgb(m_center.Setup.DefaultFontColor); pnlAltColor.BackColor = Color.FromArgb(m_center.Setup.AltFontColor); } }
/// <summary> /// Constructor. /// </summary> public AboutDialog(ScoreCenter center) { InitializeComponent(); Version v = Assembly.GetExecutingAssembly().GetName().Version; lblVersion.Text = v.ToString(4); if (center.Scores.Items != null) { foreach (string tt in ScoreFactory.Instance.GetScoreTypes()) { AddCategory(tt, center.Scores.Items.Where(sc => sc.GetType().Name == tt + "Score").Count()); } lvwSummary.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); } }
/// <summary> /// Reads the settings. /// </summary> /// <param name="file">The setting file.</param> /// <param name="allowException">True to rethrow any exceptions.</param> /// <returns>The settings objects.</returns> public static ScoreCenter ReadSettings(string file, bool allowException) { ScoreCenter scores = null; try { AppDomain.CurrentDomain.AssemblyResolve += Tools.CurrentDomain_AssemblyResolve; using (FileStream tr = new FileStream(file, FileMode.Open)) { XmlSerializer xml = new XmlSerializer(typeof(ScoreCenter)); scores = (ScoreCenter)xml.Deserialize(tr); } if (scores.Setup != null && scores.Setup.AutoRefresh == null) { scores.Setup.AutoRefresh = new AutoRefreshSettings(); scores.Setup.AutoRefresh.Value = 30; } if (scores.Scores != null && scores.Scores.Items != null) { foreach (BaseScore s in scores.Scores.Items) { if (String.IsNullOrEmpty(s.Id)) { s.Id = GenerateId(); } } } } catch (Exception) { if (allowException) { throw; } scores = null; } finally { AppDomain.CurrentDomain.AssemblyResolve -= Tools.CurrentDomain_AssemblyResolve; } return(scores); }
public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) { string name = DefaultPluginName; string filename = Config.GetFile(Config.Dir.Config, ScoreCenterPlugin.SettingsFileName); ScoreCenter center = Tools.ReadSettings(filename, false); if (center.Setup != null) { name = center.Setup.Name; } strButtonText = name; strButtonImage = String.Empty; strButtonImageFocus = String.Empty; strPictureImage = "hover_score center.png"; return(true); }
/// <summary> /// Reads the settings. /// </summary> /// <param name="url"></param> /// <param name="allowException">True to rethrow any exceptions.</param> /// <returns>The settings objects.</returns> public static ScoreCenter ReadOnlineSettings(string url, bool allowException) { ScoreCenter scores = null; Stream response = null; try { AppDomain.CurrentDomain.AssemblyResolve += Tools.CurrentDomain_AssemblyResolve; WebClient client = new WebClient(); response = client.OpenRead(url); using (StreamReader sr = new StreamReader(response, Encoding.UTF8)) { XmlSerializer xml = new XmlSerializer(typeof(ScoreCenter)); scores = (ScoreCenter)xml.Deserialize(sr); } foreach (BaseScore s in scores.Scores.Items) { if (String.IsNullOrEmpty(s.Id)) { s.Id = GenerateId(); } } client.Dispose(); } catch (Exception exc) { Tools.LogError("Error in ReadOnlineSettings", exc); if (allowException) { throw; } scores = null; } finally { AppDomain.CurrentDomain.AssemblyResolve -= Tools.CurrentDomain_AssemblyResolve; } return(scores); }
public static void BuildScoreList(ThreeStateTreeView tree, ScoreCenter center, bool show) { tree.Nodes.Clear(); if (center == null || center.Scores.Items == null) { return; } tree.BeginUpdate(); Dictionary <string, ThreeStateTreeNode> nodes = new Dictionary <string, ThreeStateTreeNode>(center.Scores.Items.Count()); foreach (BaseScore sc in center.Scores.Items) { ThreeStateTreeNode node = new ThreeStateTreeNode(sc.Name); node.Tag = sc; nodes.Add(sc.Id, node); if (!sc.IsFolder() && sc.enable && show) { node.Checked = true; node.State = CheckBoxState.Checked; } } foreach (KeyValuePair <string, ThreeStateTreeNode> pair in nodes) { ThreeStateTreeNode node = pair.Value; BaseScore sc = node.Tag as BaseScore; if (String.IsNullOrEmpty(sc.Parent)) { tree.Nodes.Add(node); } else { if (nodes.ContainsKey(sc.Parent)) { nodes[sc.Parent].Nodes.Add(node); } } } RefreshTreeState(tree.Nodes); tree.EndUpdate(); tree.Sort(); }
/// <summary> /// Constructor. /// </summary> /// <param name="scores"></param> /// <param name="center"></param> public LiveCenter(IEnumerable <BaseScore> scores, ScoreCenter center) { m_scores = scores; #if DEBUG Rule r = new Rule(); r.Column = 2; r.Operator = Operation.EqualTo; r.Action = RuleAction.ReplaceText; r.Value = "b,zz"; GenericScore sc = m_scores.First() as GenericScore; sc.Rules = new Rule[1]; sc.Rules[0] = r; #endif m_center = center; this.WorkerReportsProgress = false; this.WorkerSupportsCancellation = true; this.SleepTimer = m_center.Setup.LiveCheckDelay * 60000; }
/// <summary> /// Save the settings to a file. /// </summary> /// <param name="file">The file tosave to.</param> /// <param name="scores">The objects to serialize.</param> /// <param name="backup">True to backup the previous file.</param> /// <param name="keepVirtual">Keep the virtual scores.</param> public static void SaveSettings(string file, ScoreCenter scores, bool backup, bool keepVirtual) { // backup if (backup && File.Exists(file)) { File.Copy(file, file + ".bak", true); } var originalList = scores.Scores.Items; if (!keepVirtual) { // remove children from virtual scores scores.Scores.Items = scores.Scores.Items.Where(p => !p.IsVirtual()).ToArray(); } foreach (BaseScore sc in scores.Scores.Items) { if (sc.LiveConfig != null) { if (sc.LiveConfig.IsNull()) { sc.LiveConfig = null; } } } try { using (TextWriter tw = new StreamWriter(file)) { XmlSerializer xml = new XmlSerializer(typeof(ScoreCenter)); xml.Serialize(tw, scores); } } finally { // restore list scores.Scores.Items = originalList; } }
private static void UpdateIcons(ScoreCenter center) { // create list including all icons List <string> icons = new List <string>(); icons.AddRange(center.Scores.Items.Select(sc => sc.Image)); // check if an icon is missing bool missing = false; foreach (string image in icons.Distinct()) { string fileName = Config.GetFile(Config.Dir.Thumbs, "ScoreCenter", image + ".png"); if (String.IsNullOrEmpty(image) == false && File.Exists(fileName) == false) { missing = true; break; } } if (missing) { // DL zip string url = center.Setup.UpdateUrl; url = url.Substring(0, url.LastIndexOf("/") + 1) + "ScoreCenter.zip"; string zipFileName = Config.GetFile(Config.Dir.Thumbs, "ScoreCenter.zip"); try { using (WebClient client = new WebClient()) { client.DownloadFile(url, zipFileName); ReadZip(zipFileName, center.OverrideIcons()); } } finally { File.Delete(zipFileName); } } }
private bool m_reload; // false /// <summary> /// Constructor. /// </summary> /// <param name="center">The score center to use.</param> /// <param name="selectUpdate">True to select the update tab.</param> public OptionsDialog(ScoreCenter center, bool selectUpdate) { InitializeComponent(); m_center = center; DataTable dt = new DataTable(); dt.Columns.Add("Name"); dt.Columns.Add("Value"); List <string> allready = new List <string>(); if (center.Parameters != null) { foreach (var p in center.Parameters) { dt.Rows.Add(p.name, p.Value); allready.Add(p.name); } } List <string> plist = m_center.GetParameters(); foreach (string pp in plist) { if (!allready.Contains(pp)) { dt.Rows.Add(pp, ""); } } dataGridView1.DataSource = dt; dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Ascending); if (selectUpdate) { tbcOptions.SelectedTab = tpgUpdate; } }
private void ScoreCenterConfig_Load(object sender, EventArgs e) { try { m_settings = Config.GetFile(Config.Dir.Config, ScoreCenterPlugin.SettingsFileName); m_center = Tools.ReadSettings(m_settings, true); BuildScoreList(tvwScores, m_center, true); } catch (Exception exc) { MessageBox.Show(exc.Message, Properties.Resources.ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } if (m_center.Scores.Items == null || m_center.Scores.Items.Length == 0) { DialogResult res = MessageBox.Show("The settings is empty, do you want to download the online settings?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { ShowOptions(true); } } }
private static bool OnlineUpdate(ScoreCenter center, string url, ImportOptions options) { bool result = false; if (String.IsNullOrEmpty(url) == false) { ScoreCenter online = Tools.ReadOnlineSettings(url, false); if (online != null) { int nb = ExchangeManager.Import(center, online, options); Tools.LogMessage("Imported: {0}", nb); result = (nb > 0); // if scores imported if (result) { // check icons UpdateIcons(center); } } } return(result); }
/// <summary> /// Constructor. /// </summary> /// <param name="center">The source to export.</param> public ExportDialog(ScoreCenter center) { InitializeComponent(); m_center = center; }
/// <summary> /// Import scores from an XML file. /// </summary> /// <param name="center">The existing center.</param> /// <param name="fileName">The path of the file to import.</param> /// <param name="mergeOptions">The merge options.</param> public static void Import(ScoreCenter center, string fileName, ImportOptions mergeOptions) { ScoreCenter imported = Tools.ReadSettings(fileName, true); ExchangeManager.Import(center, imported, mergeOptions); }
private void SetLiveSettings() { if (m_liveEnabled) { // stop the live File.Delete(Config.GetFile(Config.Dir.Config, LiveSettingsFileName)); m_liveEnabled = false; SetLiveStatus(); } else { // create a settings with all live settings var liveList = m_center.Scores.Items.Where(sc => sc.IsLive() && !sc.IsVirtual()); if (liveList.Count() == 0) { // no live score configure GUIDialogText ww = (GUIDialogText)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TEXT); ww.SetHeading("ScoreCenter"); ww.SetText(LocalizationManager.GetString(Labels.NoLiveScore)); ww.DoModal(GetID); } else { // create new score center ScoreCenter liveExport = new ScoreCenter(); liveExport.Parameters = m_center.Parameters; liveExport.Setup = m_center.Setup; liveExport.Styles = m_center.Styles; // clone the scores foreach (BaseScore sc in liveList) { m_center.ReadChildren(sc); } liveList = m_center.Scores.Items.Where(sc => sc.IsLive() && sc.IsScore()); var ll = new List <BaseScore>(liveList.Count()); foreach (BaseScore score in liveList) { BaseScore livescore = score.Clone(score.Id); BaseScore parent = m_center.FindScore(livescore.Parent); if (parent != null) { // use parent icon and name for notification livescore.Name = parent.LocName; livescore.Image = parent.Image; } livescore.ApplyRangeValue(true); ll.Add(livescore); } liveExport.Scores = new ScoreCenterScores(); liveExport.Scores.Items = ll.ToArray(); // create the settings Tools.SaveSettings(Config.GetFile(Config.Dir.Config, LiveSettingsFileName), liveExport, false, true); // update the status m_liveEnabled = true; SetLiveStatus(); } } }