|
| 1 | +namespace HonkTTS.Installer.Models; |
| 2 | + |
| 3 | +public sealed class InstallConfig |
| 4 | +{ |
| 5 | + public string BaseDir { get; } |
| 6 | + |
| 7 | + public string PythonDir => Path.Combine(BaseDir, "python"); |
| 8 | + public string VenvDir => Path.Combine(BaseDir, "venv"); |
| 9 | + public string EspeakDir => Path.Combine(BaseDir, "espeak-ng"); |
| 10 | + public string ServerDir => Path.Combine(BaseDir, "server"); |
| 11 | + public string TempDir => Path.Combine(BaseDir, ".tmp"); |
| 12 | + |
| 13 | + public string PythonExe => Path.Combine(PythonDir, PlatformInfo.PythonExeRelative); |
| 14 | + public string PipExe => Path.Combine(PythonDir, PlatformInfo.PipExeRelative); |
| 15 | + public string VenvPythonExe => Path.Combine(VenvDir, PlatformInfo.VenvPythonRelative); |
| 16 | + public string VenvPipExe => Path.Combine(VenvDir, PlatformInfo.VenvPipRelative); |
| 17 | + |
| 18 | + public string EspeakExe => Path.Combine(EspeakDir, PlatformInfo.IsWindows ? "espeak-ng.exe" : "espeak-ng"); |
| 19 | + public string EspeakDataDir => Path.Combine(EspeakDir, "espeak-ng-data"); |
| 20 | + |
| 21 | + public string StartScript => PlatformInfo.IsWindows |
| 22 | + ? Path.Combine(BaseDir, "start_tts.bat") |
| 23 | + : Path.Combine(BaseDir, "start_tts.sh"); |
| 24 | + public string TestScript => PlatformInfo.IsWindows |
| 25 | + ? Path.Combine(BaseDir, "test_tts.bat") |
| 26 | + : Path.Combine(BaseDir, "test_tts.sh"); |
| 27 | + public string MetadataFile => Path.Combine(BaseDir, "config.json"); |
| 28 | + |
| 29 | + public string SourceServerDir { get; } |
| 30 | + |
| 31 | + public InstallManifest? InstalledManifest { get; set; } |
| 32 | + |
| 33 | + public InstallManifest ExpectedManifest { get; set; } = new(); |
| 34 | + |
| 35 | + public static InstallConfig FromArgs(string[] args) |
| 36 | + { |
| 37 | + var baseDir = args.Length > 0 |
| 38 | + ? args[0] |
| 39 | + : Path.Combine( |
| 40 | + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), |
| 41 | + "StationHub", "Installations", "tts"); |
| 42 | + |
| 43 | + return new InstallConfig(baseDir); |
| 44 | + } |
| 45 | + |
| 46 | + private InstallConfig(string baseDir) |
| 47 | + { |
| 48 | + BaseDir = Path.GetFullPath(baseDir); |
| 49 | + |
| 50 | + // The server source is located relative to the installer binary or CWD. |
| 51 | + var candidates = new[] |
| 52 | + { |
| 53 | + Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", "..", "server"), |
| 54 | + Path.Combine(AppContext.BaseDirectory, "server"), |
| 55 | + Path.Combine(Directory.GetCurrentDirectory(), "server"), |
| 56 | + Path.Combine(Directory.GetCurrentDirectory(), "..", "server"), |
| 57 | + }; |
| 58 | + |
| 59 | + SourceServerDir = candidates |
| 60 | + .Select(d => Path.GetFullPath(d)) |
| 61 | + .FirstOrDefault(d => File.Exists(Path.Combine(d, "tts_server.py"))) |
| 62 | + ?? throw new DirectoryNotFoundException( |
| 63 | + "Could not locate server/tts_server.py relative to the installer."); |
| 64 | + } |
| 65 | +} |
0 commit comments