Skip to content

Commit dbf9490

Browse files
Copilottautcony
andcommitted
Fix Core library compilation - all platform-independent code now builds
Co-authored-by: tautcony <8295052+tautcony@users.noreply.github.com>
1 parent 54f2061 commit dbf9490

File tree

8 files changed

+1025
-2
lines changed

8 files changed

+1025
-2
lines changed

ChapterTool.Core/Util/ChapterData/IfoParser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace ChapterTool.Util.ChapterData
2323
using System;
2424
using System.Diagnostics;
2525
using System.IO;
26+
using static ChapterTool.Util.Logger;
2627

2728
public static class IfoParser
2829
{

ChapterTool.Core/Util/CueSharp.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,11 @@ private void ParseIndex(string line, int trackOn)
402402
}
403403
else if (indexType == "PREGAP")
404404
{
405-
Tracks[trackOn].PreGap = new Index(0, minutes, seconds, frames);
405+
Tracks[trackOn].PreGap = new Cue.Types.Index(0, minutes, seconds, frames);
406406
}
407407
else if (indexType == "POSTGAP")
408408
{
409-
Tracks[trackOn].PostGap = new Index(0, minutes, seconds, frames);
409+
Tracks[trackOn].PostGap = new Cue.Types.Index(0, minutes, seconds, frames);
410410
}
411411
}
412412

ChapterTool.Core/Util/LanguageSelectionContainer.cs

Lines changed: 480 additions & 0 deletions
Large diffs are not rendered by default.

ChapterTool.Core/Util/Logger.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// ****************************************************************************
2+
// Public Domain
3+
// code from http://sourceforge.net/projects/gmkvextractgui/
4+
// ****************************************************************************
5+
namespace ChapterTool.Util
6+
{
7+
using System;
8+
using System.Text;
9+
10+
public static class Logger
11+
{
12+
private static readonly StringBuilder LogContext = new StringBuilder();
13+
14+
public static string LogText => LogContext.ToString();
15+
16+
public static event Action<string, DateTime> LogLineAdded;
17+
18+
public static void Log(string message)
19+
{
20+
var actionDate = DateTime.Now;
21+
string logMessage = $"{actionDate:[yyyy-MM-dd][HH:mm:ss]} {message}";
22+
LogContext.AppendLine(logMessage);
23+
OnLogLineAdded(logMessage, actionDate);
24+
}
25+
26+
private static void OnLogLineAdded(string lineAdded, DateTime actionDate)
27+
{
28+
LogLineAdded?.Invoke(lineAdded, actionDate);
29+
}
30+
}
31+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// ****************************************************************************
2+
//
3+
// Copyright (C) 2014-2016 TautCony (TautCony@vcb-s.com)
4+
//
5+
// This program is free software; you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation; either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program; if not, write to the Free Software
17+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
//
19+
// ****************************************************************************
20+
21+
namespace ChapterTool.Util
22+
{
23+
/// <summary>
24+
/// Cross-platform notification placeholder
25+
/// UI layer should implement actual notification display
26+
/// </summary>
27+
public static class Notification
28+
{
29+
public enum NotificationType
30+
{
31+
Info,
32+
Warning,
33+
Error,
34+
Question
35+
}
36+
37+
public enum NotificationResult
38+
{
39+
OK,
40+
Cancel,
41+
Yes,
42+
No
43+
}
44+
45+
// Event that UI layer can subscribe to
46+
public static event Action<string, string, NotificationType>? OnNotification;
47+
48+
// Event that UI layer can subscribe to for questions
49+
public static event Func<string, string, NotificationType, NotificationResult>? OnQuestion;
50+
51+
// Event that UI layer can subscribe to for input
52+
public static event Func<string, string, string, string?>? OnInputBox;
53+
54+
public static NotificationResult ShowInfo(string message, string title = "Information")
55+
{
56+
OnNotification?.Invoke(title, message, NotificationType.Info);
57+
return NotificationResult.OK;
58+
}
59+
60+
public static NotificationResult ShowWarning(string message, string title = "Warning")
61+
{
62+
OnNotification?.Invoke(title, message, NotificationType.Warning);
63+
return NotificationResult.OK;
64+
}
65+
66+
public static NotificationResult ShowError(string message, string title = "Error")
67+
{
68+
OnNotification?.Invoke(title, message, NotificationType.Error);
69+
return NotificationResult.OK;
70+
}
71+
72+
public static NotificationResult ShowQuestion(string message, string title = "Question")
73+
{
74+
return OnQuestion?.Invoke(title, message, NotificationType.Question) ?? NotificationResult.No;
75+
}
76+
77+
public static string? InputBox(string prompt, string title = "Input", string defaultValue = "")
78+
{
79+
return OnInputBox?.Invoke(title, prompt, defaultValue);
80+
}
81+
}
82+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// ****************************************************************************
2+
//
3+
// Copyright (C) 2014-2016 TautCony (TautCony@vcb-s.com)
4+
//
5+
// This program is free software; you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation; either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program; if not, write to the Free Software
17+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
//
19+
// ****************************************************************************
20+
21+
namespace ChapterTool.Util
22+
{
23+
using System;
24+
using System.Collections.Generic;
25+
using System.IO;
26+
using System.Text.Json;
27+
28+
/// <summary>
29+
/// Cross-platform settings storage using JSON file
30+
/// Replaces Registry-based storage from WinForms version
31+
/// </summary>
32+
public static class RegistryStorage
33+
{
34+
private static readonly string SettingsPath = Path.Combine(
35+
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
36+
"ChapterTool",
37+
"settings.json");
38+
39+
private static Dictionary<string, string> _settings = new();
40+
private static bool _loaded = false;
41+
42+
static RegistryStorage()
43+
{
44+
EnsureSettingsDirectory();
45+
}
46+
47+
private static void EnsureSettingsDirectory()
48+
{
49+
var directory = Path.GetDirectoryName(SettingsPath);
50+
if (directory != null && !Directory.Exists(directory))
51+
{
52+
Directory.CreateDirectory(directory);
53+
}
54+
}
55+
56+
private static void LoadSettings()
57+
{
58+
if (_loaded) return;
59+
60+
try
61+
{
62+
if (File.Exists(SettingsPath))
63+
{
64+
var json = File.ReadAllText(SettingsPath);
65+
_settings = JsonSerializer.Deserialize<Dictionary<string, string>>(json) ?? new();
66+
}
67+
}
68+
catch
69+
{
70+
_settings = new Dictionary<string, string>();
71+
}
72+
73+
_loaded = true;
74+
}
75+
76+
private static void SaveSettings()
77+
{
78+
try
79+
{
80+
EnsureSettingsDirectory();
81+
var json = JsonSerializer.Serialize(_settings, new JsonSerializerOptions { WriteIndented = true });
82+
File.WriteAllText(SettingsPath, json);
83+
}
84+
catch
85+
{
86+
// Silently fail if we can't save settings
87+
}
88+
}
89+
90+
public static string? Load(string subkey, string name)
91+
{
92+
// Legacy compatibility - combine subkey and name
93+
return Load($"{subkey}_{name}");
94+
}
95+
96+
public static string? Load(string name)
97+
{
98+
LoadSettings();
99+
return _settings.TryGetValue(name, out var value) ? value : null;
100+
}
101+
102+
public static void Save(string value, string subkey, string name)
103+
{
104+
// Legacy compatibility - combine subkey and name
105+
Save($"{subkey}_{name}", value);
106+
}
107+
108+
public static void Save(string name, string value)
109+
{
110+
LoadSettings();
111+
_settings[name] = value;
112+
SaveSettings();
113+
}
114+
115+
public static void Delete(string name)
116+
{
117+
LoadSettings();
118+
if (_settings.ContainsKey(name))
119+
{
120+
_settings.Remove(name);
121+
SaveSettings();
122+
}
123+
}
124+
}
125+
}

ChapterTool.Core/Util/ToolKits.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
namespace ChapterTool.Util
2121
{
2222
using System;
23+
using System.Text;
2324
using System.Text.RegularExpressions;
2425

2526
public static class ToolKits
@@ -75,5 +76,23 @@ public static string ToCueTimeStamp(this TimeSpan input)
7576
if (frames > 99) frames = 99;
7677
return $"{(input.Hours * 60) + input.Minutes:D2}:{input.Seconds:D2}:{frames:D2}";
7778
}
79+
80+
/// <summary>
81+
/// Detects BOM and converts byte array to UTF string
82+
/// </summary>
83+
/// <param name="buffer">Byte array to convert</param>
84+
/// <returns>UTF string</returns>
85+
public static string? GetUTFString(this byte[] buffer)
86+
{
87+
if (buffer == null) return null;
88+
if (buffer.Length <= 3) return Encoding.UTF8.GetString(buffer);
89+
if (buffer[0] == 0xEF && buffer[1] == 0xBB && buffer[2] == 0xBF)
90+
return new UTF8Encoding(false).GetString(buffer, 3, buffer.Length - 3);
91+
if (buffer[0] == 0xFF && buffer[1] == 0xFE)
92+
return Encoding.Unicode.GetString(buffer);
93+
if (buffer[0] == 0xFE && buffer[1] == 0xFF)
94+
return Encoding.BigEndianUnicode.GetString(buffer);
95+
return Encoding.UTF8.GetString(buffer);
96+
}
7897
}
7998
}

0 commit comments

Comments
 (0)