Move code out of main form ctor

This commit is contained in:
Travis Nickles 2018-08-17 02:20:53 -05:00
parent 0358002e72
commit 3df7f24a7b
2 changed files with 37 additions and 34 deletions

View File

@ -358,7 +358,43 @@ namespace DS4Windows
catch { /* Skip setting culture that we cannot set */ }
}
public static void CreateStdActions()
{
XmlDocument xDoc = new XmlDocument();
try
{
string[] profiles = Directory.GetFiles(appdatapath + @"\Profiles\");
string s = string.Empty;
//foreach (string s in profiles)
for (int i = 0, proflen = profiles.Length; i < proflen; i++)
{
s = profiles[i];
if (Path.GetExtension(s) == ".xml")
{
xDoc.Load(s);
XmlNode el = xDoc.SelectSingleNode("DS4Windows/ProfileActions");
if (el != null)
{
if (string.IsNullOrEmpty(el.InnerText))
el.InnerText = "Disconnect Controller";
else
el.InnerText += "/Disconnect Controller";
}
else
{
XmlNode Node = xDoc.SelectSingleNode("DS4Windows");
el = xDoc.CreateElement("ProfileActions");
el.InnerText = "Disconnect Controller";
Node.AppendChild(el);
}
xDoc.Save(s);
LoadActions();
}
}
}
catch { }
}
public static event EventHandler<EventArgs> ControllerStatusChange; // called when a controller is added/removed/battery or touchpad mode changes/etc.
public static void ControllerStatusChanged(object sender)

View File

@ -216,40 +216,7 @@ namespace DS4Windows
if (!LoadActions()) //if first no actions have been made yet, create PS+Option to D/C and save it to every profile
{
XmlDocument xDoc = new XmlDocument();
try
{
string[] profiles = Directory.GetFiles(appdatapath + @"\Profiles\");
string s = string.Empty;
//foreach (string s in profiles)
for (int i = 0, proflen = profiles.Length; i < proflen; i++)
{
s = profiles[i];
if (Path.GetExtension(s) == ".xml")
{
xDoc.Load(s);
XmlNode el = xDoc.SelectSingleNode("DS4Windows/ProfileActions");
if (el != null)
{
if (string.IsNullOrEmpty(el.InnerText))
el.InnerText = "Disconnect Controller";
else
el.InnerText += "/Disconnect Controller";
}
else
{
XmlNode Node = xDoc.SelectSingleNode("DS4Windows");
el = xDoc.CreateElement("ProfileActions");
el.InnerText = "Disconnect Controller";
Node.AppendChild(el);
}
xDoc.Save(s);
LoadActions();
}
}
}
catch { }
Global.CreateStdActions();
}
bool start = true;