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); } }
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(); }