Skip to content

Commit

Permalink
Added default voicer install
Browse files Browse the repository at this point in the history
  • Loading branch information
EX3exp committed Sep 29, 2024
1 parent 20c4839 commit eb96de6
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 5 deletions.
1 change: 0 additions & 1 deletion Mirivoice.Desktop/Mirivoice.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Mirivoice\Mirivoice.csproj" />
</ItemGroup>
Expand Down
7 changes: 5 additions & 2 deletions Mirivoice.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Mirivoice.Mirivoice.Core;
using Serilog;
using System;
using System.IO;
using System.Text;

namespace Mirivoice.Desktop;
Expand All @@ -19,7 +20,7 @@ public static void Main(string[] args)

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
InitLogging();
initMirivoice();
InitMirivoice();
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);

}
Expand Down Expand Up @@ -49,12 +50,14 @@ public static void InitLogging()
Log.Information("Logging initialized.");
}

public static void initMirivoice()
public static void InitMirivoice()
{

Log.Information("Mirivoice init");
MainManager.Instance.Initialize();


}


}
Binary file added Mirivoice/Assets/DefaultVoicers/Miri.z01
Binary file not shown.
Binary file added Mirivoice/Assets/DefaultVoicers/Miri.zip
Binary file not shown.
84 changes: 83 additions & 1 deletion Mirivoice/Mirivoice.Core/Managers/MainManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
using Mirivoice.Mirivoice.Core.Managers;
using Mirivoice.Mirivoice.Core.Utils;
using Serilog;
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Threading.Tasks;
using SharpCompress;
using VYaml.Serialization;
using SharpCompress.Archives;


namespace Mirivoice.Mirivoice.Core
{
Expand All @@ -32,6 +36,7 @@ public class MainManager : SingletonBase<MainManager>
public void Initialize()
{
CheckDirs();
UpdateDefaultVoicers();
LoadVoicerManager();
LoadSetting();
InitializationTask = Task.Run(() => {
Expand All @@ -57,8 +62,60 @@ public void LoadSetting()
Setting.Save();
}
}
private static void DeleteExtractedZip(string zipFilePath)
{
// deletes zip file and split files
string baseFileName = Path.GetFileNameWithoutExtension(zipFilePath);
string directory = Path.GetDirectoryName(zipFilePath);

// delete zip file
if (File.Exists(zipFilePath))
{
File.Delete(zipFilePath);
Console.WriteLine($"Deleted: {zipFilePath}");
}

// delete split files
int index = 1;
while (true)
{
string splitFilePath = Path.Combine(directory, $"{baseFileName}.z{index:D2}");
if (File.Exists(splitFilePath))
{
File.Delete(splitFilePath);
index++;
}
else
{
break;
}
}
}
public void UpdateDefaultVoicers()
{
Log.Information("Updating default voicers.");
string dirName = Path.Combine(MainManager.Instance.PathM.AssetsPath, "DefaultVoicers");
if (Directory.Exists(dirName))
{
foreach (string file in Directory.GetFiles(dirName))
{
if (Path.GetExtension(file).Equals(".zip", StringComparison.OrdinalIgnoreCase))
{
try
{
ExtractSplitZip(file, PathM.VoicerPath);
Log.Information($"Successfully extracted {file}.");
}
catch (Exception ex)
{
Log.Error($"Error extracting {file}: {ex.Message}");
}
}
}
}
}




public string ReadTxtFile(string txtPath)
{
Expand Down Expand Up @@ -95,7 +152,32 @@ public static void CheckDirs()
}
}

public static void ExtractSplitZip(string zipFilePath, string extractPath)
{
using (var archive = ArchiveFactory.Open(zipFilePath))
{
foreach (var entry in archive.Entries)
{
if (!entry.IsDirectory)
{
string entryPath = Path.Combine(extractPath, entry.Key);

string directoryPath = Path.GetDirectoryName(entryPath);
if (!string.IsNullOrEmpty(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}

using (var stream = File.OpenWrite(entryPath))
{
entry.WriteTo(stream);
}
}
}
}

DeleteExtractedZip(zipFilePath);
}

}

Expand Down
3 changes: 2 additions & 1 deletion Mirivoice/Mirivoice.Core/Managers/PathManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ public class PathManager
public string DataPath { get; private set; }
public string CachePath { get; private set; }
public string SettingsPath { get; private set; }

public string RecentFilesPath { get; private set; }
public bool HomePathIsAscii { get; private set; }
public bool IsInstalled { get; private set; }

public string LogFilePath => Path.Combine(DataPath, "Logs", "log.txt");
public string VoicerPath => Path.Combine(RootPath, "Voicers");

public string AssetsPath => Path.Combine(RootPath, "Assets");

public PathManager()
{
Expand Down
8 changes: 8 additions & 0 deletions Mirivoice/Mirivoice.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
<AvaloniaResource Include="Assets\**" />
</ItemGroup>

<ItemGroup>
<None Update="Assets\DefaultVoicers\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<None Remove="Assets\mirivoice-logo - 복사.ico" />
</ItemGroup>
Expand Down Expand Up @@ -96,6 +102,8 @@
</AvaloniaXaml>
</ItemGroup>



<ItemGroup>
<Compile Update="Views\LineBoxView.axaml.cs">
<DependentUpon>LineBoxView.axaml</DependentUpon>
Expand Down

0 comments on commit eb96de6

Please sign in to comment.