Skip to content

Commit

Permalink
- Fixed the issue that files would be lost when only one disabled vpk…
Browse files Browse the repository at this point in the history
… content was left.

- Setting: added option "Compression level".
  • Loading branch information
Starfelll committed Jun 18, 2024
1 parent 2b492e6 commit de3574f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 28 deletions.
2 changes: 1 addition & 1 deletion NekoVpk/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class App : Application
{
public static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();

public const string Version = "0.1.4.1";
public const string Version = "0.1.5.0";

public const string VersionSuffix = "-Beta";

Expand Down
2 changes: 1 addition & 1 deletion NekoVpk/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<value />
</setting>
<setting name="CompressionLevel" serializeAs="String">
<value>1</value>
<value>3</value>
</setting>
</NekoVpk.NekoSettings>
</userSettings>
Expand Down
2 changes: 1 addition & 1 deletion NekoVpk/NekoSettings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion NekoVpk/NekoSettings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Value Profile="(Default)" />
</Setting>
<Setting Name="CompressionLevel" Type="System.Int16" Scope="User">
<Value Profile="(Default)">1</Value>
<Value Profile="(Default)">3</Value>
</Setting>
</Settings>
</SettingsFile>
43 changes: 22 additions & 21 deletions NekoVpk/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,15 @@ private async void Button_AssetTagModifiedPanel_Apply(object? sender, Avalonia.I

if (AddonList.SelectedItem is AddonAttribute att && DataContext is MainViewModel vm)
{

Package? pkg = null;
SevenZipExtractor? extractor = null;
SevenZipCompressor? compressor = null;
DirectoryInfo? tmpDir = null;
try
{
pkg = att.LoadPackage(vm.GameDir);
DirectoryInfo tmpDir = new (pkg.FileName + "_nekotmp");
tmpDir = new(pkg.FileName + "_nekotmp");

if (tmpDir.Exists)
tmpDir.Delete(true);
Expand All @@ -221,9 +225,6 @@ private async void Button_AssetTagModifiedPanel_Apply(object? sender, Avalonia.I

FileInfo tmpFile = new(Path.Join(tmpDir.FullName, att.FileName + ".nekotmp"));

SevenZipExtractor? extractor = null;
SevenZipCompressor? compressor = null;

// find neko7z
foreach (var entry in pkg.Entries)
{
Expand All @@ -247,15 +248,14 @@ private async void Button_AssetTagModifiedPanel_Apply(object? sender, Avalonia.I

if (extractor is not null)
{
foreach (var zipFile in extractor.ArchiveFileData)
foreach (var zipFileData in extractor.ArchiveFileData)
{
if (zipFile.IsDirectory) continue;
foreach (var tag in ModifiedAssetTags.Keys)
{
if (tag.Enable && tag.Proporty.IsMatch(zipFile.FileName))
if (tag.Enable && tag.Proporty.IsMatch(zipFileData.FileName))
{
disableZipFiles.Add(zipFile.Index, null);
vpkFiles.Add(zipFile.FileName);
disableZipFiles.Add(zipFileData.Index, null);
vpkFiles.Add(zipFileData.FileName);
break;
}
}
Expand All @@ -281,8 +281,7 @@ private async void Button_AssetTagModifiedPanel_Apply(object? sender, Avalonia.I
{
CompressionMode = extractor is null ? CompressionMode.Create : CompressionMode.Append,
ArchiveFormat = OutArchiveFormat.SevenZip,
//CompressionLevel = (CompressionLevel)NekoSettings.Default.CompressionLevel,
CompressionLevel = CompressionLevel.Ultra,
CompressionLevel = (CompressionLevel)NekoSettings.Default.CompressionLevel,
CompressionMethod = CompressionMethod.Lzma2,
EventSynchronization = EventSynchronizationStrategy.AlwaysSynchronous,
};
Expand All @@ -298,7 +297,14 @@ private async void Button_AssetTagModifiedPanel_Apply(object? sender, Avalonia.I
}
}
// delete file in archive
int originCount = extractor.ArchiveFileNames.Count;
compressor.ModifyArchive(tmpFile.FullName, disableZipFiles);

extractor = new SevenZipExtractor(tmpFile.FullName, InArchiveFormat.SevenZip);
if ( extractor.ArchiveFileNames.Count != originCount - disableZipFiles.Count)
{
throw new Exception("Modified archive has an unexpected number of files.");
}
}

// move vpk files to zip
Expand All @@ -316,7 +322,7 @@ private async void Button_AssetTagModifiedPanel_Apply(object? sender, Avalonia.I
}


if (zipFiles.Count > 0 || (extractor != null && disableZipFiles.Count < extractor.ArchiveFileData.Count))
if (zipFiles.Count > 0 || disableZipFiles.Count > 0)
{
tmpFile.Refresh();
pkg.AddFile(pkg.GenNekoDir() + "0.neko7z", tmpFile);
Expand All @@ -340,24 +346,19 @@ private async void Button_AssetTagModifiedPanel_Apply(object? sender, Avalonia.I
// update UI
ModifiedAssetTags.Clear();
AssetTagModifiedPanel.IsVisible = false;

clean:
extractor?.Dispose();
if (tmpDir.Exists)
tmpDir.Delete(true);
return;
cancel:
CancelAssetTagChange();
goto clean;
}
catch (Exception ex)
{
CancelAssetTagChange();
Debug.WriteLine(ex);
throw ex;
}
finally
{
pkg?.Dispose();
extractor?.Dispose();
if (tmpDir is not null && tmpDir.Exists)
tmpDir.Delete(true);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions NekoVpk/Views/SettingsWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
<Button Classes="Tertiary" Height="32" Click="Browser_Click">...</Button>
</StackPanel>
<StackPanel Grid.Row="1">
<Label>CompressionLevel</Label>
<!--<ComboBox Name="ComboBox_CompressionLevel" Width="100" SelectedIndex="{Binding CompressionLevel}">
<Label>Compression level</Label>
<ComboBox Name="ComboBox_CompressionLevel" Width="100" SelectedIndex="{Binding CompressionLevel}">
<ComboBoxItem>Fast</ComboBoxItem>
<ComboBoxItem>Low</ComboBoxItem>
<ComboBoxItem>Normal</ComboBoxItem>
<ComboBoxItem>High</ComboBoxItem>
<ComboBoxItem>Ultra</ComboBoxItem>
</ComboBox>-->
</ComboBox>
</StackPanel>
</Grid>
</StackPanel>
Expand Down
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
* ![](https://github.com/Starfelll/NekoVpk/blob/main/image/%7B5B7F3754-AEAB-478f-90C3-D0D2934D8D8A%7D.png)


## Special Dependencies
https://github.com/Starfelll/ValvePak/tree/nekovpk
https://github.com/Starfelll/ValveKeyValue/tree/nekovpk


## changelog
#### v0.1.5
- Fixed the issue that files would be lost when only one disabled vpk content was left.
- Setting: added option "Compression level".
#### v0.1.4
- Store window size and position.
- Tag: merge zoey_light, francis_light, bill_death_pose, modify script to vscript.
Expand Down

0 comments on commit de3574f

Please sign in to comment.