Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 51397f1

Browse files
authored
Java installation removal (#119)
* remove old lysis java system and added basicpawn's lysis.net * improve decompiling message * remove unnecesary DLLs from new lysis
1 parent 6906237 commit 51397f1

12 files changed

+80
-259
lines changed
6.34 MB
Binary file not shown.
946 KB
Binary file not shown.

Resources/Misc/Lysis/IKVM.Runtime.dll

869 KB
Binary file not shown.
29.5 KB
Binary file not shown.

Resources/Misc/Lysis/lysis-java.dll

255 KB
Binary file not shown.

Resources/Misc/Lysis/lysis-java.jar

-285 KB
Binary file not shown.

Spcode.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@
204204
<Compile Include="Utils\Models\Hotkey.cs" />
205205
<Compile Include="Utils\Models\HotkeyInfo.cs" />
206206
<Compile Include="Utils\HotkeyUtils.cs" />
207-
<Compile Include="Utils\JavaInstallation.cs" />
208207
<Compile Include="Utils\NamesHelper.cs" />
209208
<Compile Include="Utils\ObjectBrowserUtils.cs" />
210209
<Compile Include="Utils\Paths.cs" />
@@ -593,9 +592,7 @@
593592
<Version>1.1.0</Version>
594593
</PackageReference>
595594
</ItemGroup>
596-
<ItemGroup>
597-
<Folder Include="Resources\Translations\" />
598-
</ItemGroup>
595+
<ItemGroup />
599596
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
600597
<PropertyGroup>
601598
<PreBuildEvent>cd ..\..\Deploy\

UI/MainWindow/MainWindowCommands.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,23 @@ private void Command_TidyCode(bool All)
609609
/// </summary>
610610
private async void Command_Decompile()
611611
{
612+
ProgressDialogController? msg = null;
612613
try
613614
{
614-
var decomp = new DecompileUtil();
615-
await decomp.DecompilePlugin();
615+
var file = DecompileUtil.GetFile();
616+
msg = await this.ShowProgressAsync(Translate("Decompiling") + "...", file.Name, false, MetroDialogOptions);
617+
msg.SetIndeterminate();
618+
ProcessUITasks();
619+
TryLoadSourceFile(DecompileUtil.GetDecompiledPlugin(file), out _);
616620
}
617621
catch (Exception ex)
618622
{
619623
await this.ShowMessageAsync(Translate("Error"), ex.Message, settings: MetroDialogOptions);
620624
}
625+
finally
626+
{
627+
await msg.CloseAsync();
628+
}
621629
}
622630

623631
/// <summary>

UI/MainWindow/MainWindowObjectBrowser.cs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ private async void OBItemDecompile_Click(object sender, RoutedEventArgs e)
142142
var selectedItemFile = ((ObjectBrowser.SelectedItem as TreeViewItem)?.Tag as ObjectBrowserTag)?.Value;
143143
if (selectedItemFile != null)
144144
{
145-
await new DecompileUtil().DecompilePlugin(selectedItemFile);
145+
var fInfo = new FileInfo(selectedItemFile);
146+
var msg = await this.ShowProgressAsync(Translate("Decompiling") + "...", fInfo.Name, false, MetroDialogOptions);
147+
msg.SetIndeterminate();
148+
ProcessUITasks();
149+
TryLoadSourceFile(DecompileUtil.GetDecompiledPlugin(fInfo), out _);
150+
await msg.CloseAsync();
146151
}
147152
}
148153

@@ -160,26 +165,26 @@ private void OBItemRename_Click(object sender, RoutedEventArgs e)
160165
ObjectBrowser.ContextMenu = null;
161166

162167
// If we didn't receive an empty name...
163-
if (!string.IsNullOrEmpty(renameWindow.NewName))
168+
if (string.IsNullOrEmpty(renameWindow.NewName))
164169
{
165-
var oldFileInfo = new FileInfo(fileTag.Value);
166-
var newFileInfo = new FileInfo(oldFileInfo.DirectoryName + @"\" + renameWindow.NewName);
170+
return;
171+
}
172+
var oldFileInfo = new FileInfo(fileTag.Value);
173+
var newFileInfo = new FileInfo(oldFileInfo.DirectoryName + @"\" + renameWindow.NewName);
167174

168-
// Rename file
169-
File.Move(oldFileInfo.FullName, newFileInfo.FullName);
175+
// Rename file
176+
File.Move(oldFileInfo.FullName, newFileInfo.FullName);
170177

171-
// If the new extension is not supported by SPCode, remove it from object browser
172-
// else, rename and update the item
173-
if (!FileIcons.ContainsKey(newFileInfo.Extension))
174-
{
175-
file.Visibility = Visibility.Collapsed;
176-
return;
177-
}
178-
else
179-
{
180-
fileTag.Value = newFileInfo.FullName;
181-
file.Header = BuildTreeViewItemContent(renameWindow.NewName, FileIcons[newFileInfo.Extension]);
182-
}
178+
// If the new extension is not supported by SPCode, remove it from object browser
179+
// else, rename and update the item
180+
if (!FileIcons.ContainsKey(newFileInfo.Extension))
181+
{
182+
file.Visibility = Visibility.Collapsed;
183+
}
184+
else
185+
{
186+
fileTag.Value = newFileInfo.FullName;
187+
file.Header = BuildTreeViewItemContent(renameWindow.NewName, FileIcons[newFileInfo.Extension]);
183188
}
184189
}
185190
}
@@ -578,8 +583,8 @@ private void ChangeObjectBrowserToDrives()
578583
}
579584

580585
/// <summary>
581-
/// <para> Helper function to build an expanded item's contents. </para>
582-
/// <para> It outs a TreeViewItem list to be used when using the Reload function to keep directories expanded after refreshing. </para>
586+
/// Helper function to build an expanded item's contents. <br/>
587+
/// It outs a TreeViewItem list to be used when using the Reload function to keep directories expanded after refreshing.
583588
/// </summary>
584589
/// <param name="dir">Directory to fetch contents from.</param>
585590
/// <param name="itemsToExpand">List of items that were expanded before calling this function to reload the Object Browser items.</param>

Utils/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public static class Constants
4040
public const string ErrorFilterRegex = @"^(?<File>.+?)\((?<Line>[0-9]+(\s*--\s*[0-9]+)?)\)\s*:\s*(?<Type>[a-zA-Z]+\s+([a-zA-Z]+\s+)?[0-9]+)\s*:(?<Details>.+)";
4141
public const string FileSaveFilters = @"Sourcepawn Files (*.sp *.inc)|*.sp;*.inc|All Files (*.*)|*.*";
4242
public const string FileOpenFilters = @"Sourcepawn Files (*.sp *.inc)|*.sp;*.inc|Sourcemod Plugins (*.smx)|*.smx|All Files (*.*)|*.*";
43+
public static string DecompileFileFilters = "Sourcepawn Plugins (*.smx)|*.smx";
4344
#endregion
4445

4546
#region Other

Utils/DecompileUtil.cs

Lines changed: 43 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -2,130 +2,67 @@
22
using System.Diagnostics;
33
using System.IO;
44
using System.Text;
5-
using System.Threading.Tasks;
6-
using MahApps.Metro.Controls.Dialogs;
75
using Microsoft.Win32;
8-
using SPCode.UI;
96
using static SPCode.Interop.TranslationProvider;
10-
using static SPCode.Utils.JavaInstallation;
117

128
namespace SPCode.Utils
139
{
14-
public class DecompileUtil
10+
public static class DecompileUtil
1511
{
16-
public async Task DecompilePlugin(string filePath = null)
12+
public static FileInfo GetFile()
1713
{
18-
var java = new JavaInstallation();
14+
string fileToDecompile;
1915

20-
// First we check the java version of the user, and act accordingly
21-
ProgressDialogController checkingJavaDialog = null;
22-
if (Program.MainWindow != null)
16+
var ofd = new OpenFileDialog
2317
{
24-
checkingJavaDialog = await Program.MainWindow.ShowProgressAsync(Translate("JavaInstallCheck") + "...",
25-
"", false, Program.MainWindow.MetroDialogOptions);
26-
MainWindow.ProcessUITasks();
27-
}
28-
switch (java.GetJavaStatus())
18+
Filter = Constants.DecompileFileFilters,
19+
Title = Translate("ChDecomp")
20+
};
21+
var result = ofd.ShowDialog();
22+
fileToDecompile = result.Value && !string.IsNullOrWhiteSpace(ofd.FileName) ? ofd.FileName : null;
23+
24+
if (fileToDecompile == null)
2925
{
30-
case JavaResults.Absent:
31-
{
32-
// If java is not installed, offer to download it
33-
await checkingJavaDialog.CloseAsync();
34-
if (await Program.MainWindow.ShowMessageAsync(Translate("JavaNotFoundTitle"),
35-
Translate("JavaNotFoundMessage"),
36-
MessageDialogStyle.AffirmativeAndNegative, Program.MainWindow.MetroDialogOptions) == MessageDialogResult.Affirmative)
37-
{
38-
await java.InstallJava();
39-
}
40-
return;
41-
}
42-
case JavaResults.Outdated:
43-
{
44-
// If java is outdated, offer to upgrade it
45-
await checkingJavaDialog.CloseAsync();
46-
if (await Program.MainWindow.ShowMessageAsync(Translate("JavaOutdatedTitle"),
47-
Translate("JavaOutdatedMessage"),
48-
MessageDialogStyle.AffirmativeAndNegative, Program.MainWindow.MetroDialogOptions) == MessageDialogResult.Affirmative)
49-
{
50-
await java.InstallJava();
51-
}
52-
return;
53-
}
54-
case JavaResults.Correct:
55-
{
56-
// Move on
57-
await checkingJavaDialog.CloseAsync();
58-
break;
59-
}
26+
return null;
6027
}
28+
return new FileInfo(fileToDecompile);
29+
}
6130

62-
string fileToDecompile;
63-
if (filePath == null)
31+
public static string GetDecompiledPlugin(FileInfo file)
32+
{
33+
var decompilerPath = Paths.GetLysisDirectory();
34+
var destFile = file.FullName + ".sp";
35+
var standardOutput = new StringBuilder();
36+
using var process = new Process();
37+
var si = new ProcessStartInfo
6438
{
65-
var ofd = new OpenFileDialog
66-
{
67-
Filter = "Sourcepawn Plugins (*.smx)|*.smx",
68-
Title = Translate("ChDecomp")
69-
};
70-
var result = ofd.ShowDialog();
71-
fileToDecompile = result.Value && !string.IsNullOrWhiteSpace(ofd.FileName) ? ofd.FileName : null;
72-
}
73-
else
39+
WorkingDirectory = decompilerPath,
40+
UseShellExecute = false,
41+
RedirectStandardOutput = true,
42+
RedirectStandardError = true,
43+
CreateNoWindow = true,
44+
FileName = "cmd.exe",
45+
Arguments = $"/c LysisDecompiler.exe \"{file.FullName}\"",
46+
};
47+
process.StartInfo = si;
48+
49+
if (File.Exists(destFile))
7450
{
75-
fileToDecompile = filePath;
51+
File.Delete(destFile);
7652
}
7753

78-
if (!string.IsNullOrWhiteSpace(fileToDecompile))
54+
try
7955
{
80-
var fInfo = new FileInfo(fileToDecompile);
81-
if (fInfo.Exists)
82-
{
83-
ProgressDialogController task = null;
84-
if (Program.MainWindow != null)
85-
{
86-
task = await Program.MainWindow.ShowProgressAsync(Translate("Decompiling") + "...",
87-
fInfo.FullName, false, Program.MainWindow.MetroDialogOptions);
88-
MainWindow.ProcessUITasks();
89-
}
90-
91-
// Prepare Lysis execution
92-
var destFile = fInfo.FullName + ".sp";
93-
var standardOutput = new StringBuilder();
94-
using var process = new Process();
95-
process.StartInfo.WorkingDirectory = Paths.GetLysisDirectory();
96-
process.StartInfo.UseShellExecute = false;
97-
process.StartInfo.RedirectStandardOutput = true;
98-
process.StartInfo.CreateNoWindow = true;
99-
process.StartInfo.FileName = "java";
100-
101-
process.StartInfo.Arguments = $"-jar lysis-java.jar \"{fInfo.FullName}\"";
102-
103-
// Execute Lysis, read and store output
104-
try
105-
{
106-
process.Start();
107-
while (!process.HasExited)
108-
{
109-
standardOutput.Append(process.StandardOutput.ReadToEnd());
110-
}
111-
standardOutput.Append(process.StandardOutput.ReadToEnd());
112-
File.WriteAllText(destFile, standardOutput.ToString(), Encoding.UTF8);
113-
}
114-
catch (Exception ex)
115-
{
116-
await Program.MainWindow.ShowMessageAsync($"{fInfo.Name} {Translate("FailedToDecompile")}",
117-
$"{ex.Message}", MessageDialogStyle.Affirmative,
118-
Program.MainWindow.MetroDialogOptions);
119-
}
120-
121-
// Load the decompiled file to SPCode
122-
Program.MainWindow.TryLoadSourceFile(destFile, out _, true, false, true);
123-
if (task != null)
124-
{
125-
await task.CloseAsync();
126-
}
127-
}
56+
process.Start();
57+
standardOutput.Append(process.StandardOutput.ReadToEnd());
58+
File.WriteAllText(destFile, standardOutput.ToString(), Encoding.UTF8);
12859
}
60+
catch (Exception)
61+
{
62+
throw;
63+
}
64+
65+
return destFile;
12966
}
13067
}
13168
}

0 commit comments

Comments
 (0)