private void ApplyMenuItem_Click(object sender, RoutedEventArgs e) { SkinToApply = lvSkins.SelectedItem as DDOUISkin; if (SkinToApply == null) { return; } try { if (Directory.Exists(DDOPath)) { DeleteFolder(DDOPath); } Directory.CreateDirectory(DDOPath); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Stop); return; } Cursor = Cursors.Wait; BackgroundWorker bw = new BackgroundWorker(); bw.WorkerReportsProgress = true; bw.DoWork += ApplySkin_DoWork; bw.ProgressChanged += Process_ProgressChanged; bw.RunWorkerCompleted += Process_Completed; bw.RunWorkerAsync(); }
public static DDOUISkin Load(XmlDocument doc, string rp) { try { XmlElement xe = doc.GetElementsByTagName("SkinName")[0] as XmlElement; DDOUISkin skin = new DDOUISkin() { Name = xe.GetAttribute("Name"), RootPath = rp }; if (string.IsNullOrWhiteSpace(skin.Name)) { return(null); } var mas = doc.GetElementsByTagName("Mapping"); foreach (XmlElement ma in mas) { skin.AddAsset(ma.GetAttribute("ArtAssetID"), Path.Combine(rp, ma.GetAttribute("FileName")), skin.Name); } return(skin); } catch { return(null); } }
void ProcessNewSkin(DDOUISkin skin) { DDOUISkin old = Skins.Find(s => string.Compare(s.Name, skin.Name, true) == 0); if (old != null) { Skins.Remove(old); } Skins.Add(skin); RefreshSkinList(); }
public MainWindow() { InitializeComponent(); #if DEBUG miDeveloper.IsEnabled = true; miDeveloper.SetValue(VisibilityProperty, Visibility.Visible); #else miDeveloper.IsEnabled = false; miDeveloper.SetValue(VisibilityProperty, Visibility.Hidden); #endif if (!Directory.Exists(SkinsPath)) { try { Directory.CreateDirectory(SkinsPath); } catch { MessageBox.Show("Unable to create UI skins directory in application folder!", "Application Error", MessageBoxButton.OK, MessageBoxImage.Stop); Close(); } } if (!Directory.Exists(DDOPath)) { try { Directory.CreateDirectory(DDOPath); } catch { MessageBox.Show("Unable to create the appropriate folder in your documents folder!", "Application Error", MessageBoxButton.OK, MessageBoxImage.Stop); Close(); } } miBackupSkins.IsEnabled = !string.IsNullOrWhiteSpace(SettingsManager.data.BackupPath); // scan local Skins directory for "installed" skins var skindefs = Directory.GetFiles(SkinsPath, "SkinDefinition.xml", SearchOption.AllDirectories); foreach (var sd in skindefs) { DDOUISkin skin = DDOUISkin.Load(sd); if (skin != null) { Skins.Add(skin); } } lvSkins.ItemsSource = Skins; }
private void DeleteSkin_Click(object sender, RoutedEventArgs e) { DDOUISkin skin = lvSkins.SelectedItem as DDOUISkin; if (skin == null) { return; } if (MessageBox.Show("Are you sure you want to delete " + skin.Name + "?", "Confirm Deletion", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } Skins.Remove(skin); DeleteFolder(skin.RootPath); RefreshSkinList(); }
private void RenameSkin_Click(object sender, RoutedEventArgs e) { DDOUISkin skin = lvSkins.SelectedItem as DDOUISkin; if (skin == null) { return; } RenameSkinWindow rsw = new RenameSkinWindow(skin.Name, Skins.Select(s => s.Name).ToList()); rsw.Owner = this; if (rsw.ShowDialog() == true) { string errors = skin.Rename(rsw.NewSkinName); if (!string.IsNullOrWhiteSpace(errors)) { MessageBox.Show(errors, "Rename Error", MessageBoxButton.OK, MessageBoxImage.Error); } } RefreshSkinList(); }
private void ProcessXDocs_DoWork(object sender, DoWorkEventArgs e) { ProcessErrors = new StringBuilder(); BackgroundWorker bw = sender as BackgroundWorker; StatusBarUpdate sbu; DDOUISkin skin; for (int i = 0; i < XDocsToProcess.Count; i++) { skin = new DDOUISkin(); XmlElement xe = XDocsToProcess[i].GetElementsByTagName("SkinName")[0] as XmlElement; skin.Name = xe.GetAttribute("Name"); skin.RootPath = Path.Combine(SkinsPath, skin.Name); try { if (Directory.Exists(skin.RootPath)) { if (!DeleteFolder(skin.RootPath)) { ProcessErrors.AppendLine("Unable to delete existing skin directory " + skin.RootPath); continue; } } Directory.CreateDirectory(skin.RootPath); } catch (Exception ex) { ProcessErrors.AppendLine(ex.Message); continue; } sbu.MainString = "Processing " + skin.Name; var maps = XDocsToProcess[i].GetElementsByTagName("Mapping"); sbu.ProgressBarMax = maps.Count; sbu.ProgressBarMin = 0; for (int m = 0; m < maps.Count; m++) { sbu.SecondaryString = (m + 1).ToString(); sbu.ProgressBarValue = m + 1; bw.ReportProgress(m, sbu); xe = maps[m] as XmlElement; string fn = xe.GetAttribute("FileName").Replace('/', '\\'); DDOUISkinAsset sa = skin.AddAsset(xe.GetAttribute("ArtAssetID"), Path.Combine(skin.RootPath, Path.GetFileName(fn)), skin.Name); if (sa == null) { continue; } try { File.Copy(Path.Combine(XDocPaths[i], fn), sa.AssetPath, true); } catch (Exception ex) { ProcessErrors.AppendLine(ex.Message); continue; } xe.SetAttribute("FileName", Path.GetFileName(sa.AssetPath)); } try { XDocsToProcess[i].Save(Path.Combine(skin.RootPath, "SkinDefinition.xml")); } catch (Exception ex) { ProcessErrors.AppendLine(ex.Message); continue; } Dispatcher.Invoke(new Action(() => ProcessNewSkin(skin))); } XDocPaths.Clear(); XDocsToProcess.Clear(); }