Skip to content

Commit

Permalink
fix bugs & remove embedded ffmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura6264 committed Jul 3, 2024
1 parent 6deaa3a commit 8fb30b4
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 363 deletions.
15 changes: 14 additions & 1 deletion App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,22 @@ public partial class App : Application
MainWindow mainWindow = null;
private void Application_Startup(object sender, StartupEventArgs e)
{
Helper.ForceInit();
// init dll
// get exe dir
var exedir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
// convert to byte
var exedir_utf8 = Helper.UTF8(exedir);
// init
Helper.ForceInit(exedir_utf8);
mainWindow = new MainWindow();
mainWindow.Show();
}

protected override void OnStartup(StartupEventArgs e)
{
SplashScreen sp = new SplashScreen("loading.png");
sp.Show(true);
base.OnStartup(e);
}
}
}
2 changes: 1 addition & 1 deletion Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class Helper
public static extern int DecFile(byte[] inFile, byte[] outDir, int SkipNoop);

[DllImport("Um.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
public static extern void ForceInit();
public static extern void ForceInit(byte[] exeDir);
public static byte[] UTF8(string input)
{
var bytes = Encoding.Default.GetBytes(input);
Expand Down
5 changes: 3 additions & 2 deletions Lib/cli/cmd/um/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ type processor struct {
}

//export ForceInit
func ForceInit() {
meta.Init()
func ForceInit(exedir *C.char) {
exedir_go := C.GoString(exedir)
meta.ForceInit(exedir_go)
}

//export DecFile
Expand Down
11 changes: 0 additions & 11 deletions Lib/cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module unlock-music.dev/cli
go 1.19

require (
github.com/bodgit/sevenzip v1.5.1
github.com/go-flac/flacpicture v0.2.0
github.com/go-flac/flacvorbis v0.1.0
github.com/go-flac/go-flac v0.3.1
Expand All @@ -18,19 +17,9 @@ require (
)

require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/bodgit/plumbing v1.3.0 // indirect
github.com/bodgit/windows v1.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
240 changes: 0 additions & 240 deletions Lib/cli/go.sum

Large diffs are not rendered by default.

Binary file removed Lib/cli/internal/meta/ffmpeg.7z
Binary file not shown.
53 changes: 53 additions & 0 deletions Lib/cli/internal/meta/ffpath.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package meta

import (
"os/exec"
"path/filepath"
"syscall"
)

var (
ffmpegPath string
ffprobePath string
)

func FFmpegPath() string { return ffmpegPath }

func FFprobePath() string { return ffprobePath }

var inited bool = false

func ForceInit(exedir string) {
if inited {
return
}

// check ffmpeg in the same directory
ffmpeg := filepath.Join(exedir, "ffmpeg.exe")
ffprobe := filepath.Join(exedir, "ffprobe.exe")
commandffmpeg := exec.Command(ffmpeg, "-version")
commandffprobe := exec.Command(ffprobe, "-version")
commandffmpeg.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
commandffprobe.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
errffmpeg := commandffmpeg.Run()
errffprobe := commandffprobe.Run()
if errffmpeg == nil && errffprobe == nil {
ffmpegPath = ffmpeg
ffprobePath = ffprobe
inited = true
return
}
// check system ffmpeg
commandffmpeg = exec.Command("ffmpeg.exe", "-version")
commandffprobe = exec.Command("ffprobe.exe", "-version")
commandffmpeg.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
commandffprobe.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
errffmpeg = commandffmpeg.Run()
errffprobe = commandffprobe.Run()
if errffmpeg == nil && errffprobe == nil {
ffmpegPath = "ffmpeg.exe"
ffprobePath = "ffprobe.exe"
inited = true
return
}
}
105 changes: 0 additions & 105 deletions Lib/cli/internal/meta/ffstatic.go

This file was deleted.

2 changes: 1 addition & 1 deletion Lib/cli/internal/meta/meta_flac.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func updateMetaFlac(_ context.Context, outPath string, m *UpdateMetadataParams)
}

// generate comment block
comment := flacvorbis.MetaDataBlockVorbisComment{Vendor: "unlock-music.dev"}
comment := flacvorbis.MetaDataBlockVorbisComment{Vendor: "unknown"}

// add metadata
title := m.Meta.GetTitle()
Expand Down
4 changes: 3 additions & 1 deletion MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
mc:Ignorable="d"
ResizeMode="CanMinimize" Icon="{StaticResource Ico}"
xmlns:ui="http://schemas.modernwpf.com/2019"
AllowDrop="True"
Drop="TODOs_Drop"
Title="UnlockMusicUI" Height="600" Width="900">
<Grid>
<ui:SimpleStackPanel Orientation="Horizontal" Margin="10">
Expand All @@ -20,7 +22,7 @@
<Button x:Name="RemoveAll" HorizontalAlignment="Left" Width="120" Height="30" Click="RemoveAll_Click">Remove All</Button>
<Button x:Name="About" HorizontalAlignment="Left" Width="120" Height="30" Click="Sort_Click">Sort</Button>
</ui:SimpleStackPanel>
<ListView MinWidth="600" x:Name="TODOs" Margin="15" AllowDrop="True" Drop="TODOs_Drop"/>
<ListView x:Name="TODOs" Margin="15"/>
</ui:SimpleStackPanel>
</Grid>
</Window>
2 changes: 1 addition & 1 deletion UnlockMusicUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</ItemGroup>

<ItemGroup>
<SplashScreen Include="loading.png" />
<Resource Include="loading.png" />
</ItemGroup>

</Project>

0 comments on commit 8fb30b4

Please sign in to comment.