Skip to content
This repository was archived by the owner on Jun 29, 2025. It is now read-only.

Commit 8662c4d

Browse files
authored
Merge pull request #36 from sepluginloader/dev
v1.10.2
2 parents 6e23e87 + cb50979 commit 8662c4d

File tree

14 files changed

+98
-32
lines changed

14 files changed

+98
-32
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,5 +355,8 @@ MigrationBackup/
355355
# SE's Bin64 folder symlinked for DLL dependencies
356356
/Bin64/
357357

358+
# Steam's workshop folder symlinked for DLL dependencies
359+
/workshop/
360+
358361
# JetBrains Rider project files
359362
.idea/

Edit-and-run-before-opening-solution.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
REM Location of your SpaceEngineers.exe
44
mklink /J Bin64 "C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64"
55

6+
REM Location of your workshop
7+
mklink /J workshop "C:\Program Files (x86)\Steam\steamapps\workshop"
8+
69
pause

PluginLoader/Data/LocalFolderPlugin.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace avaness.PluginLoader.Data
2020
public class LocalFolderPlugin : PluginData
2121
{
2222
const string XmlDataType = "Xml files (*.xml)|*.xml|All files (*.*)|*.*";
23+
const int GitTimeout = 10000;
2324

2425
public override string Source => MyTexts.GetString(MyCommonTexts.Local);
2526
private string[] sourceDirectories;
@@ -104,7 +105,11 @@ private IEnumerable<string> GetProjectFiles(string folder)
104105
// Read the output stream first and then wait.
105106
string gitOutput = p.StandardOutput.ReadToEnd();
106107
gitError = p.StandardError.ReadToEnd();
107-
p.WaitForExit();
108+
if (!p.WaitForExit(GitTimeout))
109+
{
110+
p.Kill();
111+
throw new TimeoutException("Git operation timed out.");
112+
}
108113

109114
if (p.ExitCode == 0)
110115
{
@@ -113,25 +118,25 @@ private IEnumerable<string> GetProjectFiles(string folder)
113118
}
114119
else
115120
{
116-
StringBuilder sb = new StringBuilder("An error occurred while checking git for project files. " + p.HasExited);
121+
StringBuilder sb = new StringBuilder("An error occurred while checking git for project files.").AppendLine();
117122
if (!string.IsNullOrWhiteSpace(gitError))
118123
{
119-
sb.AppendLine(" Git output: ");
124+
sb.AppendLine("Git output: ");
120125
sb.Append(gitError).AppendLine();
121126
}
122127
LogFile.WriteLine(sb.ToString());
123128
}
124129
}
125130
catch (Exception e)
126131
{
127-
StringBuilder sb = new StringBuilder("An error occurred while checking git for project files.");
132+
StringBuilder sb = new StringBuilder("An error occurred while checking git for project files.").AppendLine();
128133
if(!string.IsNullOrWhiteSpace(gitError))
129134
{
130135
sb.AppendLine(" Git output: ");
131136
sb.Append(gitError).AppendLine();
132137
}
133138
sb.AppendLine("Exception: ");
134-
sb.Append(e);
139+
sb.Append(e).AppendLine();
135140
LogFile.WriteLine(sb.ToString());
136141
}
137142

PluginLoader/Data/ModPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public WorkshopItem(string folder)
9999
public MyModContext GetModContext()
100100
{
101101
MyModContext modContext = new MyModContext();
102-
modContext.Init(new MyObjectBuilder_Checkpoint.ModItem(WorkshopId, "Steam"));
102+
modContext.Init(GetModItem());
103103
modContext.Init(WorkshopId.ToString(), null, ModLocation);
104104
return modContext;
105105
}

PluginLoader/LoaderTools.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Windows.Forms;
1616
using VRage.FileSystem;
1717
using VRage.Input;
18+
using VRage.Plugins;
1819
using VRage.Utils;
1920

2021
namespace avaness.PluginLoader
@@ -34,10 +35,12 @@ public static Form GetMainForm()
3435

3536
public static void UnloadAndRestart()
3637
{
38+
LogFile.Dispose();
3739
MySessionLoader.Unload();
3840
MySandboxGame.Config.ControllerDefaultOnStart = MyInput.Static.IsJoystickLastUsed;
3941
MySandboxGame.Config.Save();
4042
MyScreenManager.CloseAllScreensNowExcept(null);
43+
MyPlugins.Unload();
4144
Restart();
4245
}
4346

@@ -162,7 +165,7 @@ private static void OpenFileDialogThread(string title, string directory, string
162165
}
163166
catch (Exception e)
164167
{
165-
MyLog.Default.WriteLine("Error while opening file dialog: " + e);
168+
LogFile.WriteGameLog("Error while opening file dialog: " + e);
166169
}
167170
}
168171

@@ -194,7 +197,7 @@ private static void OpenFolderDialogThread(string title, string directory, Actio
194197
}
195198
catch (Exception e)
196199
{
197-
MyLog.Default.WriteLine("Error while opening file dialog: " + e);
200+
LogFile.WriteGameLog("Error while opening file dialog: " + e);
198201
}
199202
}
200203
}

PluginLoader/LogFile.cs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ public static class LogFile
1212
public static void Init(string mainPath)
1313
{
1414
string file = Path.Combine(mainPath, fileName);
15-
writer = File.CreateText(file);
15+
try
16+
{
17+
writer = File.CreateText(file);
18+
}
19+
catch
20+
{
21+
writer = null;
22+
}
1623
}
1724

1825
/// <summary>
@@ -21,18 +28,34 @@ public static void Init(string mainPath)
2128
/// </summary>
2229
public static void WriteLine(string text, bool gameLog = true)
2330
{
24-
writer?.WriteLine($"{DateTime.UtcNow:O} {text}");
25-
if(gameLog)
26-
MyLog.Default.WriteLine($"[PluginLoader] {text}");
27-
writer?.Flush();
31+
try
32+
{
33+
writer?.WriteLine($"{DateTime.UtcNow:O} {text}");
34+
if (gameLog)
35+
WriteGameLog(text);
36+
writer?.Flush();
37+
}
38+
catch
39+
{
40+
Dispose();
41+
}
42+
}
43+
44+
/// <summary>
45+
/// Writes the specifed text to the game log file.
46+
/// This function is thread safe.
47+
/// </summary>
48+
public static void WriteGameLog(string text)
49+
{
50+
MyLog.Default.WriteLine($"[PluginLoader] {text}");
2851
}
2952

3053
public static void WriteTrace(string text, bool gameLog = true)
3154
{
3255
#if DEBUG
3356
writer?.WriteLine($"{DateTime.UtcNow:O} {text}");
3457
if(gameLog)
35-
MyLog.Default.WriteLine($"[PluginLoader] {text}");
58+
LogFile.WriteGameLog($"[PluginLoader] {text}");
3659
writer?.Flush();
3760
#endif
3861
}
@@ -42,8 +65,12 @@ public static void Dispose()
4265
if (writer == null)
4366
return;
4467

45-
writer.Flush();
46-
writer.Close();
68+
try
69+
{
70+
writer.Flush();
71+
writer.Close();
72+
}
73+
catch { }
4774
writer = null;
4875
}
4976
}

PluginLoader/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.10.1.0")]
36-
[assembly: AssemblyFileVersion("1.10.1.0")]
35+
[assembly: AssemblyVersion("1.10.2.0")]
36+
[assembly: AssemblyFileVersion("1.10.2.0")]

PluginLoader/Stats/StatsClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public static PluginStats DownloadStats()
5353
{
5454
if (!PlayerConsent.ConsentGiven)
5555
{
56-
MyLog.Default.WriteLine("Downloading plugin statistics anonymously...");
56+
LogFile.WriteGameLog("Downloading plugin statistics anonymously...");
5757
votingToken = null;
5858
return SimpleHttpClient.Get<PluginStats>(StatsUri);
5959
}
6060

61-
MyLog.Default.WriteLine("Downloading plugin statistics, ratings and votes for " + PlayerHash);
61+
LogFile.WriteGameLog("Downloading plugin statistics, ratings and votes for " + PlayerHash);
6262

6363
var parameters = new Dictionary<string, string> { ["playerHash"] = PlayerHash };
6464
var pluginStats = SimpleHttpClient.Get<PluginStats>(StatsUri, parameters);

PluginLoader/Tools/SimpleHttpClient.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Net.Http;
66
using System.Text;
77
using LitJson;
8+
using VRage.Utils;
89

910
namespace avaness.PluginLoader.Tools
1011
{
@@ -29,7 +30,7 @@ public static TV Get<TV>(string url)
2930
}
3031
catch (WebException e)
3132
{
32-
LogFile.WriteLine($"REST API request failed: GET {url} [{e.Message}]");
33+
LogFile.WriteGameLog($"REST API request failed: GET {url} [{e.Message}]");
3334
return null;
3435
}
3536
}
@@ -54,7 +55,7 @@ public static TV Get<TV>(string url, Dictionary<string, string> parameters)
5455
}
5556
catch (WebException e)
5657
{
57-
LogFile.WriteLine($"REST API request failed: GET {uri} [{e.Message}]");
58+
LogFile.WriteGameLog($"REST API request failed: GET {uri} [{e.Message}]");
5859
return null;
5960
}
6061
}
@@ -70,7 +71,7 @@ public static TV Post<TV>(string url)
7071
}
7172
catch (WebException e)
7273
{
73-
LogFile.WriteLine($"REST API request failed: POST {url} [{e.Message}]");
74+
LogFile.WriteGameLog($"REST API request failed: POST {url} [{e.Message}]");
7475
return null;
7576
}
7677
}
@@ -91,7 +92,7 @@ public static TV Post<TV>(string url, Dictionary<string, string> parameters)
9192
}
9293
catch (WebException e)
9394
{
94-
LogFile.WriteLine($"REST API request failed: POST {uri} [{e.Message}]");
95+
LogFile.WriteGameLog($"REST API request failed: POST {uri} [{e.Message}]");
9596
return null;
9697
}
9798
}
@@ -111,7 +112,7 @@ public static TV Post<TV, TR>(string url, TR body)
111112
}
112113
catch (WebException e)
113114
{
114-
LogFile.WriteLine($"REST API request failed: POST {url} [{e.Message}]");
115+
LogFile.WriteGameLog($"REST API request failed: POST {url} [{e.Message}]");
115116
return null;
116117
}
117118
}
@@ -130,7 +131,7 @@ public static bool Post<TR>(string url, TR body)
130131
}
131132
catch (WebException e)
132133
{
133-
LogFile.WriteLine($"REST API request failed: POST {url} [{e.Message}]");
134+
LogFile.WriteGameLog($"REST API request failed: POST {url} [{e.Message}]");
134135
return false;
135136
}
136137
}

PluginLoader/deploy.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Rem Run this script with the full file path as argument
33

44
if [%1] == [] goto eof
55

6-
set workshop="C:\Program Files (x86)\Steam\steamapps\workshop\content\244850\2407984968"
6+
set workshop="%~dp0..\workshop\content\244850\2407984968"
77
set counter=1
88

99
Rem Wait for the file to be ready

0 commit comments

Comments
 (0)