mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-14 02:42:03 +00:00
Added ApplicationScope static class
This commit is contained in:
@@ -2,22 +2,18 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Web.Caching;
|
||||
using PckStudio.Classes.Misc;
|
||||
using SharpMSS;
|
||||
|
||||
namespace PckStudio.Classes
|
||||
{
|
||||
internal static class Binka
|
||||
{
|
||||
private static FileCacher cacher = new FileCacher(Program.AppDataCache);
|
||||
|
||||
public static int FromWav(string inputFilepath, string outputFilepath, int compressionLevel)
|
||||
{
|
||||
cacher.Cache(Properties.Resources.binka_encode, "binka_encode.exe");
|
||||
ApplicationScope.AppDataCacher.Cache(Properties.Resources.binka_encode, "binka_encode.exe");
|
||||
var process = Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = cacher.GetCachedFilepath("binka_encode.exe"),
|
||||
FileName = ApplicationScope.AppDataCacher.GetCachedFilepath("binka_encode.exe"),
|
||||
Arguments = $"\"{inputFilepath}\" \"{outputFilepath}\" -s -b{compressionLevel}",
|
||||
UseShellExecute = true,
|
||||
CreateNoWindow = true,
|
||||
@@ -34,16 +30,16 @@ namespace PckStudio.Classes
|
||||
throw new Exception("Not a Bink Audio file.");
|
||||
}
|
||||
|
||||
cacher.Cache(Properties.Resources.mss32, "mss32.dll");
|
||||
cacher.Cache(Properties.Resources.binkawin, "binkawin.asi");
|
||||
ApplicationScope.AppDataCacher.Cache(Properties.Resources.mss32, "mss32.dll");
|
||||
ApplicationScope.AppDataCacher.Cache(Properties.Resources.binkawin, "binkawin.asi");
|
||||
|
||||
LibHandle mss32LibHandle = new LibHandle(cacher.GetCachedFilepath("mss32.dll"));
|
||||
LibHandle mss32LibHandle = new LibHandle(ApplicationScope.AppDataCacher.GetCachedFilepath("mss32.dll"));
|
||||
|
||||
string destinationFilepath = Path.Combine(
|
||||
Path.GetDirectoryName(outputFilepath),
|
||||
Path.GetFileNameWithoutExtension(inputFilepath) + ".wav");
|
||||
|
||||
AILAPI.SetRedistDirectory(cacher.CacheDirectory.Replace('\\', '/'));
|
||||
AILAPI.SetRedistDirectory(ApplicationScope.AppDataCacher.CacheDirectory.Replace('\\', '/'));
|
||||
|
||||
RIBAPI.LoadApplicationProviders("*.asi");
|
||||
|
||||
|
||||
15
PCK-Studio/Internals/ApplicationScope.cs
Normal file
15
PCK-Studio/Internals/ApplicationScope.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PckStudio.Classes.Misc;
|
||||
|
||||
namespace PckStudio
|
||||
{
|
||||
internal static class ApplicationScope
|
||||
{
|
||||
public static FileCacher AppDataCacher = new FileCacher(Program.AppDataCache);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2249,18 +2249,18 @@ namespace PckStudio
|
||||
waitDiag.Show(this);
|
||||
|
||||
int convertedCounter = 0;
|
||||
foreach (string file in fileDialog.FileNames)
|
||||
foreach (string waveFilepath in fileDialog.FileNames)
|
||||
{
|
||||
string[] a = Path.GetFileNameWithoutExtension(file).Split(Path.GetInvalidFileNameChars());
|
||||
string[] a = Path.GetFileNameWithoutExtension(waveFilepath).Split(Path.GetInvalidFileNameChars());
|
||||
|
||||
string songName = string.Join("_", a);
|
||||
songName = System.Text.RegularExpressions.Regex.Replace(songName, @"[^\u0000-\u007F]+", "_"); // Replace UTF characters
|
||||
string cacheSongLoc = Path.Combine(Program.AppDataCache, songName + Path.GetExtension(file));
|
||||
string cacheSongLoc = Path.Combine(ApplicationScope.AppDataCacher.CacheDirectory, songName + Path.GetExtension(waveFilepath));
|
||||
|
||||
if (File.Exists(cacheSongLoc))
|
||||
File.Delete(cacheSongLoc);
|
||||
|
||||
using (var reader = new NAudio.Wave.WaveFileReader(file)) //read from original location
|
||||
using (var reader = new NAudio.Wave.WaveFileReader(waveFilepath)) //read from original location
|
||||
{
|
||||
var newFormat = new NAudio.Wave.WaveFormat(reader.WaveFormat.SampleRate, 16, reader.WaveFormat.Channels);
|
||||
using (var conversionStream = new NAudio.Wave.WaveFormatConversionStream(newFormat, reader))
|
||||
@@ -2274,7 +2274,7 @@ namespace PckStudio
|
||||
int exitCode = 0;
|
||||
await System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
exitCode = Classes.Binka.FromWav(cacheSongLoc, Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".binka"), 4);
|
||||
exitCode = Classes.Binka.FromWav(cacheSongLoc, Path.Combine(Path.GetDirectoryName(waveFilepath), Path.GetFileNameWithoutExtension(waveFilepath) + ".binka"), 4);
|
||||
});
|
||||
|
||||
if (exitCode != 0)
|
||||
|
||||
@@ -192,6 +192,7 @@
|
||||
<Compile Include="Classes\Misc\FileCacher.cs" />
|
||||
<Compile Include="Classes\Misc\OpenFolderDialog.cs" />
|
||||
<Compile Include="Classes\Models\DefaultModels\Steve64x64Model.cs" />
|
||||
<Compile Include="Internals\ApplicationScope.cs" />
|
||||
<Compile Include="Internals\SkinBOX.cs" />
|
||||
<Compile Include="Classes\Utils\ARC\ARCUtil.cs" />
|
||||
<Compile Include="Extensions\ImageExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user