-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDazDsx.cs
171 lines (150 loc) · 6.36 KB
/
DazDsx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace DazXmlModifier
{
class DazDsx
{
String filepathfull { get; set; }
XDocument xfile;
public String productName { get; set; }
public String globalID { get; set; }
public List<String> AssetNames { get; set; }
/// <summary>
///
/// </summary>
/// <param name="filepathfull"></param>
public DazDsx(String filepathfull)
{
this.filepathfull = filepathfull;
this.AssetNames = new List<String>();
readXmlDoc();
}
/// <summary>
///
/// </summary>
private void readXmlDoc()
{
//Load file and fill out basic variables.
this.xfile = XDocument.Load(filepathfull);
var xProductNode = xfile.Descendants().Where(n => n.Name == "Product").FirstOrDefault();
if ((xProductNode != null) & (xProductNode.FirstAttribute != null))
productName = xProductNode.FirstAttribute.Value;
var xGlobalIDNode = xfile.Descendants().Where(n => n.Name == "GlobalID").FirstOrDefault();
if ((xGlobalIDNode != null) & (xGlobalIDNode.FirstAttribute != null))
globalID = xGlobalIDNode.FirstAttribute.Value;
//This will loop through every asset to populate names.
var xAssetsNode = xfile.Descendants().Where(n => n.Name == "Assets").FirstOrDefault();
foreach (XElement xasset in xAssetsNode.Descendants("Asset"))
{
AssetNames.Add(xasset.FirstAttribute.Value);
}
}
public Boolean ProcessAssets(String assetName, String content, String cat, String comp, Boolean compBase)
{
var xAssetsNode = xfile.Descendants().Where(n => n.Name == "Assets").FirstOrDefault();
//This will loop through every asset.
foreach (XElement xasset in xAssetsNode.Descendants("Asset"))
{
String localAssetName = xasset.FirstAttribute.Value;
//Check if this is the asset we want to modify.
if (assetName != localAssetName)
continue;
Console.WriteLine(localAssetName);
//====== Content Type ======
//<ContentType VALUE="Follower/Wardrobe/Dress"/>
if (content != "")
{
xasset.Add(new XElement("ContentType", new XAttribute("VALUE", content)));
}
//====== Categories ======
//<Categories>
// < Category VALUE = "/Default/Wardrobe/Dresses" />
//</Categories>
if (cat != "")
{
XElement xcatagories = new XElement("Categories");
xcatagories.Add(new XElement("Category", new XAttribute("VALUE", cat)));
xasset.Add(xcatagories);
}
//====== Compatibilitybase ======
//<CompatibilityBase VALUE="/Belle Dress for Genesis 8 Females/Belle Dress"/>
if (compBase)
{
String baseName = localAssetName.Split('/').Last();
String info = "/" + productName + "/" + baseName.Substring(0, baseName.Length - 4);
xasset.Add(new XElement("CompatibilityBase", new XAttribute("VALUE", info)));
}
//====== Compatibility ======
//<Compatibilities>
// < Compatibility VALUE = "/Genesis 8/Female" />
//</Compatibilities>
if ((comp != "") & (comp != "Null (do not add)"))
{
XElement xcatagories = new XElement("Compatibilities");
xcatagories.Add(new XElement("Compatibility", new XAttribute("VALUE", cat)));
xasset.Add(xcatagories);
}
}
return true;
}
/// <summary>
/// DO NOT USE
/// </summary>
/// <returns></returns>
public Boolean ProcessAssets(String content, String cat, String comp, Boolean compBase)
{
var xAssetsNode = xfile.Descendants().Where(n => n.Name == "Assets").FirstOrDefault();
//This will loop through every asset.
foreach (XElement xasset in xAssetsNode.Descendants("Asset"))
{
String assetName = xasset.FirstAttribute.Value;
Console.WriteLine(assetName);
//xasset.FirstAttribute.SetValue("TESTING");
//====== Content Type ======
//<ContentType VALUE="Follower/Wardrobe/Dress"/>
if (content != "")
{
xasset.Add(new XElement("ContentType", new XAttribute("VALUE", content)));
}
//====== Categories ======
//<Categories>
// < Category VALUE = "/Default/Wardrobe/Dresses" />
//</Categories>
if (cat != "")
{
XElement xcatagories = new XElement("Categories");
xcatagories.Add(new XElement("Category", new XAttribute("VALUE", cat)));
xasset.Add(xcatagories);
}
//====== Compatibilitybase ======
if (compBase)
{
String baseName = assetName.Split('/').Last();
String info = "/" + productName + "/" + baseName.Substring(0, baseName.Length - 4);
xasset.Add(new XElement("CompatibilityBase", new XAttribute("VALUE", info)));
}
//====== Compatibility ======
if (comp != "")
{
XElement xcatagories = new XElement("Compatibilities");
xcatagories.Add(new XElement("Compatibility", new XAttribute("VALUE", cat)));
xasset.Add(xcatagories);
}
}
return true;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public Boolean saveChanges()
{
this.xfile.Save(filepathfull);
return true;
}
}
}