diff --git a/DBObj/SongData.cs b/DBObj/SongData.cs index 74a2895..5a880a6 100644 --- a/DBObj/SongData.cs +++ b/DBObj/SongData.cs @@ -1,7 +1,9 @@ using DualScreenDemo; using System; +using System.Collections.Concurrent; using System.IO; using System.Net; +using System.Net.Http; using System.Windows.Markup; namespace DBObj { @@ -75,21 +77,41 @@ namespace DBObj { try { - var check = IsFtpUriReachable(new Uri(new Uri(server), basic.getFileName()).ToString()); - Uri fullUri = new Uri(new Uri(server), basic.getFileName()); - //string fullPath = Path.Combine(server, basic.getFileName()); - //string fileName = Path.GetFileName(basic.getFileName()); - //if (File.Exists(fullPath)) - //{ - // //Console.WriteLine($"找到檔案: {fullPath}"); - // //if (!File.Exists(Application.StartupPath + fileName)) File.Copy(fullPath, Application.StartupPath + fileName); - // return true; - //} - if (check) + string fullPath = Path.Combine(server, basic.getFileName()); + string fileName = Path.GetFileName(basic.getFileName()); + string folderName = basic.getFileName().Replace(fileName, ""); + string folderPath = Application.StartupPath + "Temp"; + // Directory.CreateDirectory(folderPath); + // Directory.CreateDirectory(folderPath + "\\" +folderName); + + // bool isTooBig = FolderSizeChecker.IsFolderSizeExceeded(folderPath, 50.0); + // if (isTooBig) FolderSizeChecker.TrimFolderToSize(folderPath, 50.0); + + if (File.Exists(fullPath)) { - // Console.WriteLine($"找到檔案: {new Uri(new Uri(server), basic.getFileName())}"); + //Console.WriteLine($"找到檔案: {fullPath}"); + // if (!File.Exists(folderPath + "\\" + folderName + "\\" + fileName)) + // { + // Task copyTask = Task.Run(() => + // { + // var copyQueue = new FileCopyQueue(); + + // copyQueue.Enqueue(fullPath, folderPath + "\\" + folderName + "\\" + fileName); + // }); + + // copyTask.Wait(); // Wait for the copy to complete before returning + // } + return true; } + //var check = IsHttpAddressReachable(new Uri(new Uri(server), basic.getFileName()).ToString()); + //Uri fullUri = new Uri(new Uri(server), basic.getFileName()); + //if (check) + //{ + // // if (!File.Exists(folderPath + "\\" + fileName))PrimaryForm.Instance.HttpDownload(fullUri.ToString(), folderPath+"\\"+fileName); + // // Console.WriteLine($"找到檔案: {new Uri(new Uri(server), basic.getFileName())}"); + // return true; + //} } catch (Exception ex) { @@ -128,11 +150,11 @@ namespace DBObj foreach (var server in Utils.Env.GetSongServers()) { - if (!string.IsNullOrWhiteSpace(server)) - { - Console.WriteLine($"找到檔案: {new Uri(new Uri(server), filename)}"); - return new Uri(new Uri(server), filename); - } + if (!string.IsNullOrWhiteSpace(server)) + { + Console.WriteLine($"找到檔案: {new Uri(new Uri(server), filename)}"); + return new Uri(new Uri(server), filename); + } } // throw new InvalidOperationException("No valid server found."); @@ -159,29 +181,62 @@ namespace DBObj { return String.Format("{0} {1}", basic.getName(), state.GetDescription()); } - public bool IsFtpUriReachable(string ftpUri) + // public bool IsFtpUriReachable(string ftpUri) + // { + // try + // { + // #pragma warning disable SYSLIB0014 // 類型或成員已經過時 + // var request = (FtpWebRequest)WebRequest.Create(ftpUri); + // #pragma warning restore SYSLIB0014 // 類型或成員已經過時 + // request.Method = WebRequestMethods.Ftp.ListDirectory; // Lightweight check + // // request.Credentials = new NetworkCredential("svr", "svr"); // Replace with actual username/password + // request.Timeout = 5000; + + // using var response = (FtpWebResponse)request.GetResponse(); + // return response.StatusCode == FtpStatusCode.OpeningData || response.StatusCode == FtpStatusCode.DataAlreadyOpen; + // } + // catch (WebException ex) + // { + // if (ex.Response is FtpWebResponse ftpResponse) + // { + // Console.WriteLine($"FTP error: {ftpResponse.StatusDescription}"); + // Console.WriteLine($"FTP error: {ftpResponse.BannerMessage}"); + // return false; + // } + + // Console.WriteLine($"Connection error: {ex.Message}"); + // return false; + // } + // catch (Exception ex) + // { + // Console.WriteLine($"Unexpected error: {ex.Message}"); + // return false; + // } + // } + + public static bool IsHttpAddressReachable(string url) { try { - #pragma warning disable SYSLIB0014 // 類型或成員已經過時 - var request = (FtpWebRequest)WebRequest.Create(ftpUri); - #pragma warning restore SYSLIB0014 // 類型或成員已經過時 - request.Method = WebRequestMethods.Ftp.ListDirectory; // Lightweight check - // request.Credentials = new NetworkCredential("svr", "svr"); // Replace with actual username/password +#pragma warning disable SYSLIB0014 // 類型或成員已經過時 + var request = (HttpWebRequest)WebRequest.Create(url); +#pragma warning restore SYSLIB0014 // 類型或成員已經過時 + request.Method = "HEAD"; request.Timeout = 5000; - using var response = (FtpWebResponse)request.GetResponse(); - return response.StatusCode == FtpStatusCode.OpeningData || response.StatusCode == FtpStatusCode.DataAlreadyOpen; + using var response = (HttpWebResponse)request.GetResponse(); + return (int)response.StatusCode >= 200 && (int)response.StatusCode < 300; } catch (WebException ex) { - if (ex.Response is FtpWebResponse ftpResponse) + if (ex.Response is HttpWebResponse httpResponse) { - Console.WriteLine($"FTP error: {ftpResponse.StatusDescription}"); - return false; + Console.WriteLine($"HTTP error: {httpResponse.StatusCode} - {httpResponse.StatusDescription}"); + } + else + { + Console.WriteLine($"Connection error: {ex.Message}"); } - - Console.WriteLine($"Connection error: {ex.Message}"); return false; } catch (Exception ex) @@ -191,10 +246,6 @@ namespace DBObj } } - public static bool IsFtpUri(Uri uri) - { - return uri != null && uri.Scheme == Uri.UriSchemeFtp; - } } } \ No newline at end of file diff --git a/Env.cs b/Env.cs index 7005b8a..ed2d4fe 100644 --- a/Env.cs +++ b/Env.cs @@ -62,8 +62,10 @@ namespace Utils // .Select(s => s.Trim('\'', '"').TrimEnd('\\')) // 清理 // .ToArray(); - return new string[] { @"ftp://svr:svr@svr",@"ftp://song1:song1@svr01", @"ftp://song2:song2@svr02",@"ftp://song3:song3@svr03" }; - + // return new string[] { @"ftp://svr:svr@svr", @"ftp://song1:song1@svr01", @"ftp://song2:song2@svr02", @"ftp://song3:song3@svr03" }; + // return new string[] { @"http://svr:8080", @"http://svr01:8080", @"http://svr02:8080", @"http://svr03:8080" }; + // return new string[] { Application.StartupPath+@"\\Temp", @"\\svr01", @"\\svr02" }; + return new string[] { @"\\svr01", @"\\svr02" }; } public static string Get(string key, string fallback = "") => diff --git a/PrimaryFormParts/PrimaryForm.MultiPagePanel.cs b/PrimaryFormParts/PrimaryForm.MultiPagePanel.cs index dc863a1..2954aff 100644 --- a/PrimaryFormParts/PrimaryForm.MultiPagePanel.cs +++ b/PrimaryFormParts/PrimaryForm.MultiPagePanel.cs @@ -289,7 +289,7 @@ namespace DualScreenDemo artistLabel.AutoSize = false; // 計算文字寬度 - artistLabel.Font = new Font("微軟正黑體", 22, FontStyle.Bold); + artistLabel.Font = new Font("微軟正黑體", 24, FontStyle.Bold); Screen screen = Screen.PrimaryScreen; int screenWidth = screen.Bounds.Width; int screenHeight = screen.Bounds.Height; @@ -409,7 +409,7 @@ namespace DualScreenDemo int textLength = fullText.Length; // 計算文字寬度 - songLabel.Font = new Font("微軟正黑體", 22, FontStyle.Bold); + songLabel.Font = new Font("微軟正黑體", 24, FontStyle.Bold); songLabel.Text = fullText; songLabel.Tag = song; songLabel.AutoSize = false; @@ -455,28 +455,28 @@ namespace DualScreenDemo PictureBox icon = new PictureBox() { - Image = Image.FromFile(Path.Combine(serverPath,data["PrimaryFormBtn"]["Voice"])), + Image = Image.FromFile(Path.Combine(serverPath, data["PrimaryFormBtn"]["Voice"])), SizeMode = PictureBoxSizeMode.Zoom, - Size = new Size(26, 26), - Location = new Point(songX + 5, y + 8) + Size = new Size(30, 30), + Location = new Point(songX + 5, y + 10) }; this.Controls.Add(icon); icon.BringToFront(); // 有圖標時歌名右移 - songLabel.Location = new Point(songX + 42, y); + songLabel.Location = new Point(songX + 42, y+3); //songLabel.Size = new Size(songWidth - 47, ItemHeight - 20); songLabel.Size = new Size(700, 66); } else { // 沒有圖標時歌名置中 - songLabel.Location = new Point(songX, y); + songLabel.Location = new Point(songX, y+3); //songLabel.Size = new Size(songWidth - 10, ItemHeight - 20); songLabel.Size = new Size(700, 66); } // 歌手標籤位置調整 - artistLabel.Location = new Point(artistX, y + 33); + artistLabel.Location = new Point(artistX, y + 33 + 10); artistLabel.Size = new Size(artistWidth - 10, ItemHeight - 35); if (song.getB() != null) @@ -488,7 +488,7 @@ namespace DualScreenDemo if (artistText.Length > 3) { - artistLabel.Location = new Point(artistX - 502, y + 33); + artistLabel.Location = new Point(artistX - 502, y + 33 + 10); artistLabel.Size = new Size(artistWidth + 490, ItemHeight - 35); } @@ -496,7 +496,7 @@ namespace DualScreenDemo // 創建分隔線面板 Panel separatorPanel = new Panel { - Location = new Point(songX - 5, y + ItemHeight - 2), + Location = new Point(songX - 5, y + ItemHeight - 2 + 5), //Size = new Size(songWidth + artistWidth + 20, 2), Size = new Size(730, 2), BackColor = Color.FromArgb(80, 255, 255, 255), @@ -504,7 +504,7 @@ namespace DualScreenDemo }; // 根據文字長度設置字體大小 - int fold = 14; + int fold = 16; //if (artistText.Length > 6) // fold = 10; //else if (artistText.Length > 3) @@ -560,6 +560,8 @@ namespace DualScreenDemo artistLabel.BringToFront(); songLabel.TextAlign = ContentAlignment.TopLeft; + + this.Controls.SetChildIndex(separatorPanel, 0); } diff --git a/PrimaryFormParts/PrimaryForm.cs b/PrimaryFormParts/PrimaryForm.cs index 85f59c7..dbeda03 100644 --- a/PrimaryFormParts/PrimaryForm.cs +++ b/PrimaryFormParts/PrimaryForm.cs @@ -253,7 +253,7 @@ namespace DualScreenDemo // 取主機名稱的最後 20 個字元 (如果長度不足 20,則取全部) string displayName = "包廂" + hostName.Substring(Math.Max(0, hostName.Length - 3)) + " " + Rtime; string totalPages = multiPagePanel.totalPages.ToString() == "0" ? "1" : multiPagePanel.totalPages.ToString(); - string pageNumber = (multiPagePanel.currentPageIndex + 1).ToString() + "/" + totalPages; + string pageNumber = (multiPagePanel.currentPageIndex + 1).ToString() + "/" + totalPages+"頁"; // 基準解析度(你目前的設計基準) @@ -959,36 +959,36 @@ namespace DualScreenDemo { var data = LoadBtnConfigData(); - InitializeButton(ref newSongAlertButton, ref newSongAlertNormalBackground, ref newSongAlertActiveBackground, "newSongAlertButton", 20, 98, 105, 120, data["PrimaryFormBtn"]["AlertNormal"], data["PrimaryFormBtn"]["AlertActive"], NewSongAlertButton_Click); + InitializeButton(ref newSongAlertButton, ref newSongAlertNormalBackground, ref newSongAlertActiveBackground, "newSongAlertButton", 20, 98, 105, 118, data["PrimaryFormBtn"]["AlertNormal"], data["PrimaryFormBtn"]["AlertActive"], NewSongAlertButton_Click); - InitializeButton(ref hotPlayButton, ref hotPlayNormalBackground, ref hotPlayActiveBackground, "hotPlayButton", 137, 98, 106, 120, data["PrimaryFormBtn"]["HotNormal"], data["PrimaryFormBtn"]["HotActive"], HotPlayButton_Click); + InitializeButton(ref hotPlayButton, ref hotPlayNormalBackground, ref hotPlayActiveBackground, "hotPlayButton", 137, 98, 106, 118, data["PrimaryFormBtn"]["HotNormal"], data["PrimaryFormBtn"]["HotActive"], HotPlayButton_Click); - InitializeButton(ref singerSearchButton, ref singerSearchNormalBackground, ref singerSearchActiveBackground, "singerSearchButton", 255, 98, 106, 120, data["PrimaryFormBtn"]["SingerNormal"], data["PrimaryFormBtn"]["SingerActive"], SingerSearchButton_Click); + InitializeButton(ref singerSearchButton, ref singerSearchNormalBackground, ref singerSearchActiveBackground, "singerSearchButton", 255, 98, 106, 118, data["PrimaryFormBtn"]["SingerNormal"], data["PrimaryFormBtn"]["SingerActive"], SingerSearchButton_Click); - InitializeButton(ref songSearchButton, ref songSearchNormalBackground, ref songSearchActiveBackground, "songSearchButton", 373, 98, 106, 120, data["PrimaryFormBtn"]["SongNormal"], data["PrimaryFormBtn"]["SongActive"], SongSearchButton_Click); + InitializeButton(ref songSearchButton, ref songSearchNormalBackground, ref songSearchActiveBackground, "songSearchButton", 373, 98, 106, 118, data["PrimaryFormBtn"]["SongNormal"], data["PrimaryFormBtn"]["SongActive"], SongSearchButton_Click); - InitializeButton(ref languageSearchButton, ref languageSearchNormalBackground, ref languageSearchActiveBackground, "languageSearchButton", 491, 98, 106, 120, data["PrimaryFormBtn"]["LangNormal"], data["PrimaryFormBtn"]["LangActive"], LanguageSongSelectionButton_Click); + InitializeButton(ref languageSearchButton, ref languageSearchNormalBackground, ref languageSearchActiveBackground, "languageSearchButton", 491, 98, 106, 118, data["PrimaryFormBtn"]["LangNormal"], data["PrimaryFormBtn"]["LangActive"], LanguageSongSelectionButton_Click); - InitializeButton(ref groupSearchButton, ref groupSearchNormalBackground, ref groupSearchActiveBackground, "groupSearchButton", 608, 98, 106, 120, data["PrimaryFormBtn"]["GroupNormal"], data["PrimaryFormBtn"]["GroupActive"], GroupSongSelectionButton_Click); + InitializeButton(ref groupSearchButton, ref groupSearchNormalBackground, ref groupSearchActiveBackground, "groupSearchButton", 608, 98, 106, 118, data["PrimaryFormBtn"]["GroupNormal"], data["PrimaryFormBtn"]["GroupActive"], GroupSongSelectionButton_Click); - InitializeButton(ref categorySearchButton, ref categorySearchNormalBackground, ref categorySearchActiveBackground, "categorySearchButton", 726, 98, 106, 120, data["PrimaryFormBtn"]["CategNormal"], data["PrimaryFormBtn"]["CategActive"], CategorySearchButton_Click); + InitializeButton(ref categorySearchButton, ref categorySearchNormalBackground, ref categorySearchActiveBackground, "categorySearchButton", 726, 98, 106, 118, data["PrimaryFormBtn"]["CategNormal"], data["PrimaryFormBtn"]["CategActive"], CategorySearchButton_Click); serviceBellButton = new Button { Text = "" }; - ConfigureButton(serviceBellButton, 843, 98, 107, 120, + ConfigureButton(serviceBellButton, 843, 98, 107, 118, new Bitmap(Path.Combine(serverPath, data["PrimaryFormBtn"]["BellNormal"])), new Bitmap(Path.Combine(serverPath, data["PrimaryFormBtn"]["BellActive"])), new Bitmap(Path.Combine(serverPath, data["PrimaryFormBtn"]["BellActive"])), (sender, e) => OnServiceBellButtonClick(sender, e)); - InitializeButton(ref orderedSongsButton, ref orderedSongsNormalBackground, ref orderedSongsActiveBackground, "orderedSongsButton", 961, 98, 107, 120, data["PrimaryFormBtn"]["OrderSongNormal"], data["PrimaryFormBtn"]["OrderSongActive"], OrderedSongsButton_Click); + InitializeButton(ref orderedSongsButton, ref orderedSongsNormalBackground, ref orderedSongsActiveBackground, "orderedSongsButton", 961, 98, 107, 118, data["PrimaryFormBtn"]["OrderSongNormal"], data["PrimaryFormBtn"]["OrderSongActive"], OrderedSongsButton_Click); - InitializeButton(ref myFavoritesButton, ref myFavoritesNormalBackground, ref myFavoritesActiveBackground, "myFavoritesButton", 1079, 98, 107, 120, data["PrimaryFormBtn"]["FavoriteNormal"], data["PrimaryFormBtn"]["FavoriteActive"], MyFavoritesButton_Click); + InitializeButton(ref myFavoritesButton, ref myFavoritesNormalBackground, ref myFavoritesActiveBackground, "myFavoritesButton", 1079, 98, 107, 118, data["PrimaryFormBtn"]["FavoriteNormal"], data["PrimaryFormBtn"]["FavoriteActive"], MyFavoritesButton_Click); - InitializeButton(ref promotionsButton, ref promotionsNormalBackground, ref promotionsActiveBackground, "promotionsButton", 1197, 98, 107, 120, data["PrimaryFormBtn"]["PromotNormal"], data["PrimaryFormBtn"]["PromotActive"], promotionsButton_Click); + InitializeButton(ref promotionsButton, ref promotionsNormalBackground, ref promotionsActiveBackground, "promotionsButton", 1197, 98, 107, 118, data["PrimaryFormBtn"]["PromotNormal"], data["PrimaryFormBtn"]["PromotActive"], promotionsButton_Click); - InitializeButton(ref deliciousFoodButton, ref deliciousFoodNormalBackground, ref deliciousFoodActiveBackground, "deliciousFoodButton", 1315, 98, 107, 120, data["PrimaryFormBtn"]["FoodNormal"], data["PrimaryFormBtn"]["FoodActive"], DeliciousFoodButton_Click); + InitializeButton(ref deliciousFoodButton, ref deliciousFoodNormalBackground, ref deliciousFoodActiveBackground, "deliciousFoodButton", 1315, 98, 107, 118, data["PrimaryFormBtn"]["FoodNormal"], data["PrimaryFormBtn"]["FoodActive"], DeliciousFoodButton_Click); mobileSongRequestButton = new Button { Text = "" }; diff --git a/Program.cs b/Program.cs index 70eaaa4..b43d03a 100644 --- a/Program.cs +++ b/Program.cs @@ -14,7 +14,7 @@ namespace DualScreenDemo private static PrimaryForm primaryForm; // 儲存實例的參考 public static Room room = new Room(); - public static string verSion = "Server V2.10 202509031254"; + public static string verSion = "Server V2.10 202509051440"; [STAThread] static void Main()