diff --git a/Env.cs b/Env.cs index bb28717..3af24f0 100644 --- a/Env.cs +++ b/Env.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; using System.IO; +using System.Net.Security; +using DualScreenDemo; +using HeartbeatSender; namespace Utils { @@ -26,7 +29,6 @@ namespace Utils { KtvPath = path; Console.WriteLine("找到設定檔:" + configPath); - foreach (var line in File.ReadAllLines(configPath)) { var trimmed = line.Trim(); @@ -58,7 +60,7 @@ namespace Utils // .ToArray(); return new string[] { @"\\svr01", @"\\svr02" }; - + } public static string Get(string key, string fallback = "") => @@ -94,10 +96,10 @@ namespace Utils } public static string GetDBConnection() { - return $"Server={Get("DBServer", "localhost")};Port={Get("DBPort", "3306")};Database={Get("Database", "test")};User={Get("DBUser", "root")};Password={Get("DBPassword", "")};"; + // return $"Server={Get("DBServer", "localhost")};Port={Get("DBPort", "3306")};Database={Get("Database", "test")};User={Get("DBUser", "root")};Password={Get("DBPassword", "")};"; + return $"Server={heartbeatSender.DbData["DBServer"]};Port={heartbeatSender.DbData["DBPort"]};Database={heartbeatSender.DbData["Database"]};User={heartbeatSender.DbData["DBUser"]};Password={heartbeatSender.DbData["DBPassword"]};"; } - // 如需支援更多型別可自行擴充:GetFloat, GetDouble, GetDateTime 等 } } diff --git a/HeartbeatSender.cs b/HeartbeatSender.cs index c8d6672..1587ca9 100644 --- a/HeartbeatSender.cs +++ b/HeartbeatSender.cs @@ -18,11 +18,12 @@ public class heartbeatSender private string branchName = ""; private string heartbeatDomain = ""; private CancellationTokenSource? cancellationTokenSource; - + public static Dictionary DbData= new Dictionary() ; public heartbeatSender() { this.heartbeatDomain = Utils.Env.Get("HeartBeatUrl", ""); - + bool loginSuccess = LoginAndGetTokenAsync().GetAwaiter().GetResult(); + Console.WriteLine(loginSuccess ? "心跳登入成功" : "心跳登入失敗"); // 在建構子中啟動背景心跳任務 _ = Task.Run(() => StartAsync()); } @@ -77,6 +78,15 @@ public class heartbeatSender { token = data.GetProperty("token").GetString()!; branchName = data.GetProperty("branch_name").GetString()!; + var Dbdatas = data.GetProperty("other_set"); + + if (Dbdatas.ValueKind == JsonValueKind.Object) + { + foreach (JsonProperty property in Dbdatas.EnumerateObject()) + { + DbData.Add(property.Name.ToString(), property.Value.ToString()); + } + } return true; } diff --git a/PrimaryFormParts/PrimaryForm.MultiPagePanel.cs b/PrimaryFormParts/PrimaryForm.MultiPagePanel.cs index 3f8a160..7834615 100644 --- a/PrimaryFormParts/PrimaryForm.MultiPagePanel.cs +++ b/PrimaryFormParts/PrimaryForm.MultiPagePanel.cs @@ -289,7 +289,7 @@ namespace DualScreenDemo artist.Name; artistLabel.Text = artistText; artistLabel.Tag = artist; - artistLabel.AutoSize = true; + artistLabel.AutoSize = false; // 計算文字寬度 artistLabel.Font = new Font("微軟正黑體", 22, FontStyle.Bold); @@ -315,8 +315,8 @@ namespace DualScreenDemo artistLabel.ForeColor = Color.White; // 標籤座標設定 artistLabel.Location = new Point(singerX, y); - artistLabel.Size = new Size(singerWidth + 20, ItemHeight); - + // artistLabel.Size = new Size(singerWidth + 20, ItemHeight); + artistLabel.Size = new Size(700, 66); Panel separatorPanel = new Panel { Location = new Point(singerX, y + ItemHeight), diff --git a/PrimaryFormParts/PrimaryForm.PromotionsAndMenuPanel.cs b/PrimaryFormParts/PrimaryForm.PromotionsAndMenuPanel.cs index 97a7c88..b341187 100644 --- a/PrimaryFormParts/PrimaryForm.PromotionsAndMenuPanel.cs +++ b/PrimaryFormParts/PrimaryForm.PromotionsAndMenuPanel.cs @@ -23,8 +23,8 @@ namespace DualScreenDemo private List LoadImagesFromFolder(string folderName) { List images = new(); - string folderPath = Utils.Env.GetPath(folderName, ""); - + // string folderPath = Utils.Env.GetPath(folderName, ""); + string folderPath = serverPath+"//"+folderName; if (folderPath.Equals("")) return images; string[] imageFiles = Directory.GetFiles(folderPath, "*.jpg"); diff --git a/PrimaryFormParts/PrimaryForm.cs b/PrimaryFormParts/PrimaryForm.cs index 52b28a6..207549e 100644 --- a/PrimaryFormParts/PrimaryForm.cs +++ b/PrimaryFormParts/PrimaryForm.cs @@ -9,6 +9,8 @@ using Timer = System.Windows.Forms.Timer; using IniParser.Model; using IniParser; using System.Text; +using System.Net.Http; +using System.Threading.Tasks; namespace DualScreenDemo @@ -128,7 +130,35 @@ namespace DualScreenDemo private int _currentPage { get; set; } = 0; private int _totalPages { get; set; } - string serverPath = Utils.Env.GetPath("", ""); + // string serverPath = Utils.Env.GetPath("", ""); + string serverPath = Application.StartupPath; + +// async Task GetBitmapFromUriAsync(Uri uri) +// { +// using HttpClient client = new HttpClient(); +// byte[] imageBytes = await client.GetByteArrayAsync(uri); + +// MemoryStream ms = new MemoryStream(imageBytes); +// Bitmap bitmap = new Bitmap(ms); +// Bitmap clonedBitmap = new Bitmap(bitmap); +// ms.Dispose(); + +// return clonedBitmap; +// } + + +// private async void LoadBackgroundImage() +// { +// var data = LoadBtnConfigData(); +// var hostdata = LoadBtnConfigData(); +// string test = hostdata["HeartBeatUrl"] + "/" + data["PrimaryFormBtn"]["AlertNormal1"]; +// Console.WriteLine(test); +// Uri remoteUri = new Uri("http://zqd.superstar.dnsnet.cc/themes/superstar/button/1.主類別/主類別上方_新歌快報(未按).png"); + +// Bitmap bitmap = await GetBitmapFromUriAsync(remoteUri); +// this.BackgroundImage = bitmap; +// this.BackgroundImageLayout = ImageLayout.Stretch; // Optional +// } public int currentPage { @@ -2344,7 +2374,18 @@ namespace DualScreenDemo return parser.ReadData(reader); } } + private IniData LoadConfigData() + { + var parser = new FileIniDataParser(); + string iniFilePath = Path.Combine(serverPath, "config.ini"); + + // 使用 UTF-8 讀取 INI 檔案並解析內容 + using (var reader = new StreamReader(iniFilePath, Encoding.UTF8)) + { + return parser.ReadData(reader); + } + } //主畫面上排按鍵圖形狀態設置 private void UpdateButtonBackgrounds(Button activeButton, Image activeBackground) { diff --git a/Program.cs b/Program.cs index 0e80ecd..ec8948d 100644 --- a/Program.cs +++ b/Program.cs @@ -6,6 +6,7 @@ namespace DualScreenDemo { public static class Program { + public static heartbeatSender sender = new heartbeatSender(); // 定义全局变量 internal static DBObj.SQLManager songListManager; //internal static ArtistManager artistManager; @@ -19,10 +20,11 @@ namespace DualScreenDemo static void Main() { Console.WriteLine(verSion); + if (Utils.Env.GetBool("IsCursor", true)) Cursor.Hide(); AppDomain.CurrentDomain.ProcessExit += (s, e) => Cursor.Show(); //Console.WriteLine("正在與中控取得聯繫..."); - var sender = new heartbeatSender(); + var cherker=new DataCheck.PublicSongChecker(DBObj.SongList.PublicSong()); try { diff --git a/Services/MediaService.cs b/Services/MediaService.cs index 4d76216..5991c97 100644 --- a/Services/MediaService.cs +++ b/Services/MediaService.cs @@ -56,6 +56,8 @@ namespace DualScreenDemo.Services public void LoadMedia(string filePath, int audioTrackIndex = 0) { + _mediaPlayerPrimary.Pause(); + _mediaPlayerSecondary.Pause(); _media?.Dispose(); // 建立一個完整有聲音的 Media 給 secondary 播放器 @@ -159,19 +161,11 @@ namespace DualScreenDemo.Services return result; } - public async Task SetAudioTrackToAsync(int trackIndex) + public void SetAudioTrackToAsync(int trackIndex) { var audioTracks = GetAudioTracks(); if (trackIndex < 0 || trackIndex >= audioTracks.Count) return; - - if (!_mediaPlayerSecondary.IsPlaying) - { - _mediaPlayerSecondary.Play(); - await Task.Delay(500); - } - _mediaPlayerSecondary.SetAudioTrack(audioTracks[trackIndex].Id); - await Task.Delay(300); } #endregion diff --git a/themes/superstar/_www/superstar-pic/1-1.png b/themes/superstar/_www/superstar-pic/1-1.png index f94baf9..e0ab498 100644 Binary files a/themes/superstar/_www/superstar-pic/1-1.png and b/themes/superstar/_www/superstar-pic/1-1.png differ diff --git a/themes/superstar/_www/superstar-pic/1-2.png b/themes/superstar/_www/superstar-pic/1-2.png index fc387f2..e6fc7c8 100644 Binary files a/themes/superstar/_www/superstar-pic/1-2.png and b/themes/superstar/_www/superstar-pic/1-2.png differ diff --git a/themes/superstar/_www/superstar-pic/2-1.png b/themes/superstar/_www/superstar-pic/2-1.png index ccd89f7..87ee1f1 100644 Binary files a/themes/superstar/_www/superstar-pic/2-1.png and b/themes/superstar/_www/superstar-pic/2-1.png differ diff --git a/themes/superstar/_www/superstar-pic/2-2.png b/themes/superstar/_www/superstar-pic/2-2.png index df105d9..7d42f47 100644 Binary files a/themes/superstar/_www/superstar-pic/2-2.png and b/themes/superstar/_www/superstar-pic/2-2.png differ diff --git a/themes/superstar/_www/superstar-pic/5-1.png b/themes/superstar/_www/superstar-pic/5-1.png index d383ec3..6adadfd 100644 Binary files a/themes/superstar/_www/superstar-pic/5-1.png and b/themes/superstar/_www/superstar-pic/5-1.png differ diff --git a/themes/superstar/_www/superstar-pic/5-10.png b/themes/superstar/_www/superstar-pic/5-10.png index ab8380d..267bdd7 100644 Binary files a/themes/superstar/_www/superstar-pic/5-10.png and b/themes/superstar/_www/superstar-pic/5-10.png differ diff --git a/themes/superstar/_www/superstar-pic/5-11.png b/themes/superstar/_www/superstar-pic/5-11.png index 4c10f5b..ccce1a0 100644 Binary files a/themes/superstar/_www/superstar-pic/5-11.png and b/themes/superstar/_www/superstar-pic/5-11.png differ diff --git a/themes/superstar/_www/superstar-pic/5-12.png b/themes/superstar/_www/superstar-pic/5-12.png index fd16932..25a70fe 100644 Binary files a/themes/superstar/_www/superstar-pic/5-12.png and b/themes/superstar/_www/superstar-pic/5-12.png differ diff --git a/themes/superstar/_www/superstar-pic/5-2.png b/themes/superstar/_www/superstar-pic/5-2.png index 5476e48..c881178 100644 Binary files a/themes/superstar/_www/superstar-pic/5-2.png and b/themes/superstar/_www/superstar-pic/5-2.png differ diff --git a/themes/superstar/_www/superstar-pic/5-3.png b/themes/superstar/_www/superstar-pic/5-3.png index 938c254..1245e5d 100644 Binary files a/themes/superstar/_www/superstar-pic/5-3.png and b/themes/superstar/_www/superstar-pic/5-3.png differ diff --git a/themes/superstar/_www/superstar-pic/5-4.png b/themes/superstar/_www/superstar-pic/5-4.png index 36e4da2..e04d5b8 100644 Binary files a/themes/superstar/_www/superstar-pic/5-4.png and b/themes/superstar/_www/superstar-pic/5-4.png differ diff --git a/themes/superstar/_www/superstar-pic/5-5.png b/themes/superstar/_www/superstar-pic/5-5.png index 9ec44a3..d9c34ba 100644 Binary files a/themes/superstar/_www/superstar-pic/5-5.png and b/themes/superstar/_www/superstar-pic/5-5.png differ diff --git a/themes/superstar/_www/superstar-pic/5-6.png b/themes/superstar/_www/superstar-pic/5-6.png index f0b2fe9..d9c34ba 100644 Binary files a/themes/superstar/_www/superstar-pic/5-6.png and b/themes/superstar/_www/superstar-pic/5-6.png differ diff --git a/themes/superstar/_www/superstar-pic/5-7.png b/themes/superstar/_www/superstar-pic/5-7.png index aa2ebb5..aa97de6 100644 Binary files a/themes/superstar/_www/superstar-pic/5-7.png and b/themes/superstar/_www/superstar-pic/5-7.png differ diff --git a/themes/superstar/_www/superstar-pic/5-8.png b/themes/superstar/_www/superstar-pic/5-8.png index 2cdd411..a4b7904 100644 Binary files a/themes/superstar/_www/superstar-pic/5-8.png and b/themes/superstar/_www/superstar-pic/5-8.png differ diff --git a/themes/superstar/_www/superstar-pic/5-9.png b/themes/superstar/_www/superstar-pic/5-9.png index b5db33f..bcbe573 100644 Binary files a/themes/superstar/_www/superstar-pic/5-9.png and b/themes/superstar/_www/superstar-pic/5-9.png differ