Skip to content

Commit 63529e7

Browse files
committed
Version 0.9.0-Beta part 2
1 parent 0ddbf7f commit 63529e7

21 files changed

+598
-82
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,31 @@ https://github.com/Shivansps/VP.NET/blob/main/VP.NET.Examples/Program.cs
1515

1616
VP.NET.GUI
1717
=======================
18-
![VP.NET.GUI](https://i.imgur.com/Seau5Jv.png)
18+
![VP.NET.GUI](https://i.imgur.com/TTgdFiJ.png)
1919

2020
GUI Program for the VP.NET lib, supports handling .VP and .VPC files
2121

2222

2323
Current Freatures:<br />
2424
-Loading Multiple VPs and VPC<br />
2525
-Viewing VPs/VPC and navigate the folder structure<br />
26+
-Create new VP/VPCs<br />
2627
-Extracting files from regular vp and vpc<br />
2728
-Compressing and decompressing VP/VPC<br />
28-
-Comrpessing and decompression .lz41 files<br />
29+
-Compressing and decompression .lz41 files<br />
30+
-Modify VP/VPCs<br />
31+
-Enable/Disable VP compression<br />
32+
-Image file previewing supporting: DDS, PCX, TGA, JPG<br />
33+
-Animation previewing supporting: GIF and APNG<br />
34+
-Multimedia previewing supporting: WAV, MP3, OGG, MP4 via LibVLCSharp<br />
35+
-Text previewing supporting: LUA, TBM, TBL, EFF, FS2, FC2<br />
36+
-Supporting for linking external file viewers<br />
37+
<br />
38+
Feature complete as of 0.9.0-Beta<br />
39+
<br />
40+
<br />
41+
42+
Note for developers
43+
=======================
44+
LibVLC libs are only included for Windows on debug builds, for debug builds it is needed to manually copy the dlls to the output directory.<br />
45+
Linux always need to have both vlc and libvlc-dev packages<br />

VP.NET.GUI/Models/APNGHelper.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
1-
using Metsys.Bson;
2-
using System;
3-
using System.Collections.Generic;
1+
using System;
42
using System.IO;
5-
using System.Linq;
63
using System.Text;
7-
using System.Threading.Tasks;
84

95
namespace VP.NET.GUI.Models
106
{
11-
/*
12-
* Reads a stream to verify if it is a valid APNG file
13-
* Checks for acTL chuck presence. No other data loading is done.
14-
*/
7+
/// <summary>
8+
/// Lazy APNG Helper to check if png file is a apng
9+
/// </summary>
1510
public class APNGHelper
1611
{
1712
private static byte[] FrameSignature = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
1813

19-
public static bool IsApng(MemoryStream ms)
14+
/// <summary>
15+
/// Reads a stream to verify if it is a valid APNG file
16+
/// Checks for acTL chuck presence on the first 5000 bytes of data. No other data loading is done.
17+
/// Dosent close or disposes the stream.
18+
/// Throws a exception if the stream dosent contains a png file data
19+
/// </summary>
20+
/// <param name="pngStream"></param>
21+
/// <returns>true if file is apng</returns>
22+
/// <exception cref="Exception"></exception>
23+
public static bool IsApng(Stream pngStream)
2024
{
21-
if (!IsBytesEqual(ReadBytes(ms,FrameSignature.Length), FrameSignature))
25+
if (!IsBytesEqual(ReadBytes(pngStream,FrameSignature.Length), FrameSignature))
2226
throw new Exception("File signature incorrect.");
2327

24-
var s = Encoding.ASCII.GetString(ReadBytes(ms, 5000));
28+
var bufferLength = pngStream.Length < 5000 ? (int)pngStream.Length : 5000;
29+
30+
var s = Encoding.ASCII.GetString(ReadBytes(pngStream, bufferLength));
2531
if(s.Contains("acTL"))
2632
{
27-
ms.Seek(0, SeekOrigin.Begin);
33+
pngStream.Seek(0, SeekOrigin.Begin);
2834
return true;
2935
}
30-
ms.Seek(0, SeekOrigin.Begin);
36+
pngStream.Seek(0, SeekOrigin.Begin);
3137
return false;
3238
}
3339

34-
public static bool IsBytesEqual(byte[] byte1, byte[] byte2)
40+
private static bool IsBytesEqual(byte[] byte1, byte[] byte2)
3541
{
3642
if (byte1.Length != byte2.Length)
3743
return false;
@@ -44,7 +50,7 @@ public static bool IsBytesEqual(byte[] byte1, byte[] byte2)
4450
return true;
4551
}
4652

47-
public static byte[] ReadBytes(Stream ms, int count)
53+
private static byte[] ReadBytes(Stream ms, int count)
4854
{
4955
var buffer = new byte[count];
5056

VP.NET.GUI/Models/Log.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using Avalonia.Threading;
2-
using System;
3-
using System.Collections.Generic;
1+
using System;
42
using System.Diagnostics;
53
using System.IO;
6-
using System.Linq;
74
using System.Text;
85
using System.Threading.Tasks;
96

VP.NET.GUI/Models/Settings.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
using Avalonia.Controls;
2-
using System;
1+
using System;
2+
using System.Collections.Generic;
33
using System.Diagnostics.CodeAnalysis;
44
using System.IO;
55
using System.Text;
66
using System.Text.Encodings.Web;
77
using System.Text.Json;
8-
using VP.NET.GUI.ViewModels;
98

109
namespace VP.NET.GUI.Models
1110
{
11+
public class ExternalPreviewApp
12+
{
13+
public string Path { get; set; } = string.Empty;
14+
public string Arguments { get; set; } = string.Empty;
15+
public string Extension { get; set; } = string.Empty;
16+
17+
public ExternalPreviewApp(string path, string arguments, string extension)
18+
{
19+
Path = path;
20+
Arguments = arguments;
21+
Extension = extension;
22+
}
23+
}
24+
1225
/// <summary>
1326
/// Class to store VP Net GUI settings
1427
/// </summary>
@@ -28,6 +41,8 @@ public class Settings
2841
public string? ToolLastFolderToVPFolderPath { get; set; } = null;
2942
public string? ToolLastFolderToVPVPSavePath { get; set; } = null;
3043
public bool PreviewerEnabled { get; set; } = true;
44+
public bool PreviewerTextViewer { get; set; } = true;
45+
public List<ExternalPreviewApp> ExternalExtensions { get; set; } = new List<ExternalPreviewApp>();
3146

3247
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
3348
public void Load()
@@ -53,6 +68,8 @@ public void Load()
5368
ToolLastVPCompressionDestinationPath = tempSettings.ToolLastVPCompressionDestinationPath;
5469
PreviewerEnabled = tempSettings.PreviewerEnabled;
5570
LastAddFilesPath = tempSettings.LastAddFilesPath;
71+
PreviewerTextViewer = tempSettings.PreviewerTextViewer;
72+
ExternalExtensions = tempSettings.ExternalExtensions;
5673
}
5774

5875
}
@@ -63,8 +80,27 @@ public void Load()
6380
}
6481
}
6582

83+
public void Reset()
84+
{
85+
LastFileExtractionPath = null;
86+
LastVPLoadPath = null;
87+
ToolLastLZ41FileDecompressionOpenPath = null;
88+
ToolLastLZ41FileDecompressionDestinationPath = null;
89+
ToolLastLZ41FileCompressionOpenPath = null;
90+
ToolLastLZ41FileCompressionDestinationPath = null;
91+
ToolLastVPDecompressionOpenPath = null;
92+
ToolLastVPDecompressionDestinationPath = null;
93+
ToolLastVPCompressionOpenPath = null;
94+
ToolLastVPCompressionDestinationPath = null;
95+
PreviewerEnabled = true;
96+
PreviewerTextViewer = true;
97+
LastAddFilesPath = null;
98+
ExternalExtensions.Clear();
99+
Save();
100+
}
101+
66102
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
67-
public void Save(bool writeIni = true)
103+
public void Save()
68104
{
69105
try
70106
{

VP.NET.GUI/Models/Utils.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace VP.NET.GUI.Models
1212
/// </summary>
1313
public static class Utils
1414
{
15-
private static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
16-
private static readonly bool IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
17-
private static readonly bool IsMacOS = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
15+
public static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
16+
public static readonly bool IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
17+
public static readonly bool IsMacOS = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
1818

1919
public static void OpenExternal(string path)
2020
{

VP.NET.GUI/VP.NET.GUI.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<!--Avalonia doesen't support TrimMode=link currently,but we are working on that https://github.com/AvaloniaUI/Avalonia/issues/6892 -->
77
<TrimMode>copyused</TrimMode>
88
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
9-
<PublishTrimmed>true</PublishTrimmed>
109
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
1110
</PropertyGroup>
1211
<ItemGroup>
@@ -40,9 +39,11 @@
4039
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.2" />
4140
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.2" />
4241
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
43-
<PackageReference Include="LibVLCSharp" Version="3.9.3" />
42+
<PackageReference Include="LibVLCSharp" Version="3.9.3">
43+
<ExcludeAssets></ExcludeAssets>
44+
</PackageReference>
4445
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="14.6.0" />
45-
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.21" />
46+
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="VideoLAN.LibVLC.Windows" Version="3.0.21" />
4647
</ItemGroup>
4748
<ItemGroup>
4849
<ProjectReference Include="..\IonKiwi.lz4\IonKiwi.lz4.csproj" />

VP.NET.GUI/ViewModels/MainWindowViewModel.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ public MainWindowViewModel()
5454
}
5555
}
5656

57+
public void UpdatePreviewerStatus()
58+
{
59+
PrevViewVisible = settings.PreviewerEnabled;
60+
if (!settings.PreviewerEnabled && PrevViewModel != null)
61+
{
62+
PrevViewModel.Reset();
63+
}
64+
if (settings.PreviewerEnabled && PrevViewModel == null)
65+
{
66+
PrevViewModel = new PreviewerViewModel();
67+
}
68+
}
69+
5770
/// <summary>
5871
/// Add a new working file to the list of working files
5972
/// If the file is already open it will be skipped
@@ -302,29 +315,32 @@ internal async void NewFile()
302315
{
303316
try
304317
{
305-
var newPath = (await result.GetParentAsync())?.Path.LocalPath;
306-
if (settings.LastVPLoadPath != newPath)
318+
var newFolderPath = (await result.GetParentAsync())?.TryGetLocalPath();
319+
if (settings.LastVPLoadPath != newFolderPath)
307320
{
308-
settings.LastVPLoadPath = newPath;
321+
settings.LastVPLoadPath = newFolderPath;
309322
settings.Save();
310323
}
311324
}
312325
catch { }
313326
try
314327
{
328+
var path = result.TryGetLocalPath();
329+
if (path == null)
330+
throw new Exception("Unable to determine file path");
315331
var vp = new VPContainer();
316332
var ext = Path.GetExtension(result.Name);
317333
if (ext != null && ext.ToLower() == ".vpc")
318334
{
319335
vp.EnableCompression();
320336
}
321-
await vp.SaveAsAsync(result.Path.LocalPath);
337+
await vp.SaveAsAsync(path);
322338

323339
if (PrevViewModel == null && settings.PreviewerEnabled)
324340
PrevViewModel = new PreviewerViewModel(); //start previewer
325341
if (settings.PreviewerEnabled)
326342
PrevViewVisible = true;
327-
AddWorkingFile(result.Path.LocalPath);
343+
AddWorkingFile(path);
328344
}
329345
catch (Exception ex)
330346
{

0 commit comments

Comments
 (0)