File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <Project Sdk =" Microsoft.NET.Sdk" >
2+
3+ <PropertyGroup >
4+ <OutputType >Exe</OutputType >
5+ <TargetFramework >net6.0</TargetFramework >
6+ <ImplicitUsings >enable</ImplicitUsings >
7+ <Nullable >enable</Nullable >
8+ </PropertyGroup >
9+
10+ <ItemGroup >
11+ <ProjectReference Include =" ..\Fmod5Sharp\Fmod5Sharp.csproj" />
12+ </ItemGroup >
13+
14+ </Project >
Original file line number Diff line number Diff line change 1+ using System . Text ;
2+ using Fmod5Sharp ;
3+
4+ /// <summary>
5+ /// Mainly serves as an example of how to use fmod5sharp
6+ /// </summary>
7+ public static class Program
8+ {
9+ public static void Main ( string [ ] args )
10+ {
11+ var bankPath = args [ 0 ] ;
12+ var outPath = args . Length > 1 ? args [ 1 ] : $ "{ Path . GetFileNameWithoutExtension ( bankPath ) } -extracted";
13+
14+ Console . WriteLine ( "Loading bank..." ) ;
15+
16+ var bytes = File . ReadAllBytes ( bankPath ) ;
17+
18+ var index = bytes . AsSpan ( ) . IndexOf ( Encoding . ASCII . GetBytes ( "FSB5" ) ) ;
19+
20+ if ( index > 0 )
21+ {
22+ bytes = bytes . AsSpan ( index ) . ToArray ( ) ;
23+ }
24+
25+ var bank = FsbLoader . LoadFsbFromByteArray ( bytes ) ;
26+
27+ if ( Directory . Exists ( outPath ) )
28+ {
29+ Console . WriteLine ( "Removing existing output directory..." ) ;
30+ Directory . Delete ( outPath , true ) ;
31+ }
32+
33+ var outDir = Directory . CreateDirectory ( outPath ) ;
34+
35+ Console . WriteLine ( "Extracting..." ) ;
36+ var i = 0 ;
37+ foreach ( var bankSample in bank . Samples )
38+ {
39+ i ++ ;
40+ var name = bankSample . Name ?? $ "sample-{ i } ";
41+
42+ if ( ! bankSample . RebuildAsStandardFileFormat ( out var data , out var extension ) )
43+ {
44+ Console . WriteLine ( $ "Failed to extract sample { name } ") ;
45+ continue ;
46+ }
47+
48+ var filePath = Path . Combine ( outDir . FullName , $ "{ name } .{ extension } ") ;
49+ File . WriteAllBytes ( filePath , data ) ;
50+ Console . WriteLine ( $ "Extracted sample { name } ") ;
51+ }
52+ }
53+ }
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1616 .github \workflows \default .yml = .github \workflows \default .yml
1717 EndProject Section
1818EndProject
19+ Project ("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" ) = "BankExtractor" , "BankExtractor\BankExtractor.csproj" , "{38AD6124-9F67-48BC-9EB2-0B0C10A87DD7}"
20+ EndProject
1921Global
2022 GlobalSection (SolutionConfigurationPlatforms ) = preSolution
2123 Debug| Any CPU = Debug| Any CPU
@@ -34,6 +36,10 @@ Global
3436 {433DFB57-A200-4238-B3EE-B4C5FB378E83} .Debug| Any CPU .Build .0 = Debug| Any CPU
3537 {433DFB57-A200-4238-B3EE-B4C5FB378E83} .Release| Any CPU .ActiveCfg = Release| Any CPU
3638 {433DFB57-A200-4238-B3EE-B4C5FB378E83} .Release| Any CPU .Build .0 = Release| Any CPU
39+ {38AD6124-9F67-48BC-9EB2-0B0C10A87DD7} .Debug| Any CPU .ActiveCfg = Debug| Any CPU
40+ {38AD6124-9F67-48BC-9EB2-0B0C10A87DD7} .Debug| Any CPU .Build .0 = Debug| Any CPU
41+ {38AD6124-9F67-48BC-9EB2-0B0C10A87DD7} .Release| Any CPU .ActiveCfg = Release| Any CPU
42+ {38AD6124-9F67-48BC-9EB2-0B0C10A87DD7} .Release| Any CPU .Build .0 = Release| Any CPU
3743 EndGlobalSection
3844 GlobalSection (SolutionProperties ) = preSolution
3945 HideSolutionNode = FALSE
You can’t perform that action at this time.
0 commit comments