-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.cs
181 lines (160 loc) · 5.65 KB
/
MainWindow.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
172
173
174
175
176
177
178
179
180
181
using System;
using Gtk;
using SpineGTK_v1;
using System.Xml;
using System.Xml.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public partial class MainWindow : Gtk.Window
{
public MainWindow() : base(Gtk.WindowType.Toplevel)
{
Build();
string home = Environment.GetEnvironmentVariable("HOME");
if (string.IsNullOrEmpty(home))
{
var passwd = File.ReadAllLines("/etc/passwd");
var entry = passwd.FirstOrDefault(x => x.StartsWith(Environment.UserName + ":"));
if (entry != null)
{
var parts = entry.Split(':');
home = parts[5];
}
}
String path = home + "/SpineGTK/config.xml";
XmlDocument doc = new XmlDocument();
XDocument Xdoc = new XDocument(new XElement("Games"));
if (File.Exists(path))
{
Xdoc = XDocument.Load(path);
doc.Load(path);
}
else
{
Xdoc = new XDocument(new XElement("Games"));
}
XmlNodeList nodeList = doc.SelectNodes("/Games/Game");
VBox vbox = new VBox();
vbox.Spacing = 6;
foreach (XmlNode node in nodeList)
{
XmlNode childNode = node.SelectSingleNode("Name");
XmlNode imageNode = node.SelectSingleNode("Icon");
Button btn = new Button(childNode.InnerText);
btn.SetAlignment(0, 0);
if (imageNode != null)
{
Image iconImage = new Image(imageNode.InnerText);
btn.Image = iconImage;
}
btn.Clicked += OnButtonClicked;
vbox.Add(btn);
}
fixed1.Add(vbox);
}
private void OnButtonClicked(object sender, EventArgs e)
{
Button clickedButton = sender as Button;
string gameName = clickedButton.Label;
string home = Environment.GetEnvironmentVariable("HOME");
if (string.IsNullOrEmpty(home))
{
var passwd = File.ReadAllLines("/etc/passwd");
var entry = passwd.FirstOrDefault(x => x.StartsWith(Environment.UserName + ":"));
if (entry != null)
{
var parts = entry.Split(':');
home = parts[5];
}
}
// Try to give permissions for the executable file
try
{
Process process = new Process();
process.StartInfo.FileName = "/bin/bash";
process.StartInfo.Arguments = $"-c \"chmod a+rwx {home}/SpineGTK/Spine/20220517/spine\"";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.Start();
process.WaitForExit();
Console.WriteLine("File Permissions given successfully");
if (process.ExitCode != 0)
{
Console.WriteLine("Warning: File permissions not set. Try executing this Software as ROOT");
}
}
catch (Exception ex)
{
Console.WriteLine("Error: An exception occurred while trying to set file's permissions: {0}", ex.Message);
}
// Shell command to run the game
String path = home + "/SpineGTK/config.xml";
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode gameNode = doc.SelectSingleNode("/Games/Game[Name='" + gameName + "']");
if (gameNode != null)
{
XmlNode directoryNode = gameNode.SelectSingleNode("Directory");
try
{
Process process = new Process();
process.StartInfo.FileName = "/bin/bash";
process.StartInfo.Arguments = $"-c \"{home}/SpineGTK/Spine/20220517/spine {directoryNode.InnerText}\"";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
Console.WriteLine(output);
}
catch (Exception ex)
{
Console.WriteLine("ERROR: " + ex.Message);
}
}
}
public void UpdateMainWindow()
{
string home = Environment.GetEnvironmentVariable("HOME");
String path = home + "/SpineGTK/config.xml";
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNodeList nodeList = doc.SelectNodes("/Games/Game");
VBox vbox = new VBox();
vbox.Spacing = 6;
foreach (XmlNode node in nodeList)
{
XmlNode childNode = node.SelectSingleNode("Name");
XmlNode imageNode = node.SelectSingleNode("Icon");
Button btn = new Button(childNode.InnerText);
btn.SetAlignment(0, 0);
if (imageNode != null)
{
Image iconImage = new Image(imageNode.InnerText);
btn.Image = iconImage;
}
btn.Clicked += OnButtonClicked;
vbox.Add(btn);
}
fixed1.Remove(vbox);
fixed1.Add(vbox);
fixed1.ShowAll();
}
protected void OnDeleteEvent(object sender, DeleteEventArgs a)
{
Application.Quit();
a.RetVal = true;
}
protected void OnBtnAddGameClicked(object sender, EventArgs e)
{
AddGameWindow addGameWindow = new AddGameWindow();
addGameWindow.Show();
}
protected void OnBtnRemoveGameClicked(object sender, EventArgs e)
{
RemoveGameWindow removeGameWindow = new RemoveGameWindow();
removeGameWindow.Show();
}
}