From 423966f98747affbd35b6a290682fe762a6ed1ce Mon Sep 17 00:00:00 2001 From: Orange_233 <874462262@qq.com> Date: Thu, 27 Jul 2023 04:25:55 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=B0=86=E5=88=9B=E5=BB=BALog=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E4=BB=A3=E7=A0=81=E7=A7=BB=E5=88=B0ViewModeL?= =?UTF-8?q?ocator=E6=9D=A5=E8=A7=A3=E5=86=B3=E9=83=A8=E5=88=86=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E8=B0=83=E7=94=A8=E5=89=8D=E6=9C=AA=E5=88=9B=E5=BB=BA?= =?UTF-8?q?Log=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E6=AF=94=E5=A6=82=EF=BC=8C=E5=88=9A=E5=AE=89=E8=A3=85=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E5=B0=B1=E4=BD=BF=E7=94=A8=E9=9A=8F=E6=9C=BA=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=9A=84=E6=83=85=E5=86=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- View/ToastFish.xaml.cs | 10 ---------- ViewModel/ViewModelLocator.cs | 6 ++++++ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/View/ToastFish.xaml.cs b/View/ToastFish.xaml.cs index 1fee98e..0d2e71f 100644 --- a/View/ToastFish.xaml.cs +++ b/View/ToastFish.xaml.cs @@ -344,11 +344,6 @@ private void NotifyIconDoubleClick(object sender, EventArgs e) private void Begin_Click(object sender, EventArgs e) { - if (!System.IO.Directory.Exists("Log")) { - System.IO.Directory.CreateDirectory("Log"); - } - // System.IO.Directory.CreateDirectory("Log"); - var state = thread.ThreadState; WordType Words = new WordType(); @@ -446,11 +441,6 @@ private void ImportWords_Click(object sender, EventArgs e) System.Windows.Forms.MessageBox.Show("导入文件出错!"); return; } - - if (!Directory.Exists("Log")){ - System.IO.Directory.CreateDirectory("Log"); - } - var state = thread.ThreadState; diff --git a/ViewModel/ViewModelLocator.cs b/ViewModel/ViewModelLocator.cs index 9dd7b4b..8d7c189 100644 --- a/ViewModel/ViewModelLocator.cs +++ b/ViewModel/ViewModelLocator.cs @@ -14,6 +14,7 @@ using CommonServiceLocator; using GalaSoft.MvvmLight.Ioc; +using System.IO; namespace ToastFish.ViewModel { @@ -28,6 +29,11 @@ public class ViewModelLocator /// public ViewModelLocator() { + if (!Directory.Exists("Log")) + { + System.IO.Directory.CreateDirectory("Log"); + } + ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); SimpleIoc.Default.Register(); } From e54e8bf11652659daa074293c8a25742c4d88785 Mon Sep 17 00:00:00 2001 From: Orange_233 <874462262@qq.com> Date: Thu, 27 Jul 2023 05:30:29 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E8=9C=9C=E6=B1=81=E5=88=9D=E5=A7=8B=E5=8C=96=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E6=93=8D=E4=BD=9C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Mp3/PlayMp3.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/Model/Mp3/PlayMp3.cs b/Model/Mp3/PlayMp3.cs index 6962dfd..bbb3dd3 100644 --- a/Model/Mp3/PlayMp3.cs +++ b/Model/Mp3/PlayMp3.cs @@ -54,9 +54,8 @@ public string FileName { try { - TemStr = ""; - TemStr = TemStr.PadLeft(127, Convert.ToChar(" ")); - Name = Name.PadLeft(260, Convert.ToChar(" ")); + TemStr = new String('\0', 127); + Name = Name.PadLeft(260, ' '); mc.iName = value; ilong = APIClass.GetShortPathName(mc.iName, Name, Name.Length); Name = GetCurrPath(Name); @@ -87,8 +86,7 @@ public string FileName //播放 public void play() { - TemStr = ""; - TemStr = TemStr.PadLeft(127, Convert.ToChar(" ")); + TemStr = new String('\0', 127); APIClass.mciSendString("play media", TemStr, TemStr.Length, 0); //APIClass.mciSendString("play media", null, 0, 0); mc.state = State.mPlaying; @@ -96,16 +94,14 @@ public void play() //停止 public void StopT() { - TemStr = ""; - TemStr = TemStr.PadLeft(128, Convert.ToChar(" ")); + TemStr = new String('\0', 128); ilong = APIClass.mciSendString("close media", TemStr, 128, 0); ilong = APIClass.mciSendString("close all", TemStr, 128, 0); mc.state = State.mStop; } public void Puase() { - TemStr = ""; - TemStr = TemStr.PadLeft(128, Convert.ToChar(" ")); + TemStr = new String('\0', 128); ilong = APIClass.mciSendString("pause media", TemStr, TemStr.Length, 0); mc.state = State.mPuase; } @@ -121,8 +117,7 @@ public int Duration { get { - durLength = ""; - durLength = durLength.PadLeft(128, Convert.ToChar(" ")); + durLength = new String('\0', 128); APIClass.mciSendString("status media length", durLength, durLength.Length, 0); durLength = durLength.Trim(); if (durLength == "") return 0; @@ -134,8 +129,7 @@ public int CurrentPosition { get { - durLength = ""; - durLength = durLength.PadLeft(128, Convert.ToChar(" ")); + durLength = new String('\0', 128); APIClass.mciSendString("status media position", durLength, durLength.Length, 0); mc.iPos = (int)(Convert.ToDouble(durLength) / 1000f); return mc.iPos; From deb4fdd47040fbb5c7dd87476d8878bfea0b12f5 Mon Sep 17 00:00:00 2001 From: Orange_233 <874462262@qq.com> Date: Thu, 27 Jul 2023 05:35:05 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=94=A8IntPtr.Zreo=E6=9B=BF=E4=BB=A3TemSt?= =?UTF-8?q?r=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Mp3/PlayMp3.cs | 50 ++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/Model/Mp3/PlayMp3.cs b/Model/Mp3/PlayMp3.cs index bbb3dd3..1ef06de 100644 --- a/Model/Mp3/PlayMp3.cs +++ b/Model/Mp3/PlayMp3.cs @@ -21,8 +21,8 @@ public MUSIC() private string Name = ""; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] private string durLength = ""; - [MarshalAs(UnmanagedType.LPTStr, SizeConst = 128)] - private string TemStr = ""; + //[MarshalAs(UnmanagedType.LPTStr, SizeConst = 128)] + //private string TemStr = ""; int ilong; //定义播放状态枚举变量 public enum State @@ -54,7 +54,6 @@ public string FileName { try { - TemStr = new String('\0', 127); Name = Name.PadLeft(260, ' '); mc.iName = value; ilong = APIClass.GetShortPathName(mc.iName, Name, Name.Length); @@ -73,9 +72,9 @@ public string FileName } //Name = "open " + Convert.ToChar(34) + Name + Convert.ToChar(34) + " alias media"; - ilong = APIClass.mciSendString("close all", TemStr, TemStr.Length, 0); - ilong = APIClass.mciSendString(Name, TemStr, TemStr.Length, 0); - ilong = APIClass.mciSendString("set media time format milliseconds", TemStr, TemStr.Length, 0); + ilong = APIClass.mciSendString("close all", IntPtr.Zero, 0, 0); + ilong = APIClass.mciSendString(Name, IntPtr.Zero, 0, 0); + ilong = APIClass.mciSendString("set media time format milliseconds", IntPtr.Zero, 0, 0); mc.state = State.mStop; } catch @@ -86,23 +85,21 @@ public string FileName //播放 public void play() { - TemStr = new String('\0', 127); - APIClass.mciSendString("play media", TemStr, TemStr.Length, 0); - //APIClass.mciSendString("play media", null, 0, 0); + //TemStr = new String('\0', 128); + //APIClass.mciSendString("play media", TemStr, TemStr.Length, 0); + APIClass.mciSendString("play media", IntPtr.Zero, 0, 0); mc.state = State.mPlaying; } //停止 public void StopT() { - TemStr = new String('\0', 128); - ilong = APIClass.mciSendString("close media", TemStr, 128, 0); - ilong = APIClass.mciSendString("close all", TemStr, 128, 0); + ilong = APIClass.mciSendString("close media", IntPtr.Zero, 0, 0); + ilong = APIClass.mciSendString("close all", IntPtr.Zero, 0, 0); mc.state = State.mStop; } public void Puase() { - TemStr = new String('\0', 128); - ilong = APIClass.mciSendString("pause media", TemStr, TemStr.Length, 0); + ilong = APIClass.mciSendString("pause media", IntPtr.Zero, 0, 0); mc.state = State.mPuase; } private string GetCurrPath(string name) @@ -178,16 +175,23 @@ public class APIClass { [DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern int GetShortPathName( - string lpszLongPath, - string shortFile, - int cchBuffer - ); + string lpszLongPath, + string shortFile, + int cchBuffer + ); [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)] public static extern int mciSendString( - string lpstrCommand, - string lpstrReturnString, - int uReturnLength, - int hwndCallback - ); + string lpstrCommand, + string lpstrReturnString, + int uReturnLength, + int hwndCallback + ); + [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)] + public static extern int mciSendString( + string lpstrCommand, + IntPtr lpstrReturnString, + int uReturnLength, + int hwndCallback + ); } } From 97ef2b466e7dff8601daaa81c4db44763bb9809d Mon Sep 17 00:00:00 2001 From: Orange_233 <874462262@qq.com> Date: Thu, 27 Jul 2023 05:37:38 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=B0=86=E5=88=9B=E5=BB=BALog=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E7=9A=84=E4=BB=A3=E7=A0=81=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E6=94=BE=E5=88=B0MainWindow=E7=9A=84=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E4=B8=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Mp3/PlayMp3.cs | 4 ++-- View/ToastFish.xaml.cs | 5 +++++ ViewModel/ViewModelLocator.cs | 6 ------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Model/Mp3/PlayMp3.cs b/Model/Mp3/PlayMp3.cs index 1ef06de..1a7e464 100644 --- a/Model/Mp3/PlayMp3.cs +++ b/Model/Mp3/PlayMp3.cs @@ -86,8 +86,8 @@ public string FileName public void play() { //TemStr = new String('\0', 128); - //APIClass.mciSendString("play media", TemStr, TemStr.Length, 0); - APIClass.mciSendString("play media", IntPtr.Zero, 0, 0); + //APIClass.mciSendString("play media", TemStr, TemStr.Length, 0); + APIClass.mciSendString("play media", IntPtr.Zero, 0, 0); mc.state = State.mPlaying; } //停止 diff --git a/View/ToastFish.xaml.cs b/View/ToastFish.xaml.cs index 0d2e71f..51bb26b 100644 --- a/View/ToastFish.xaml.cs +++ b/View/ToastFish.xaml.cs @@ -41,6 +41,11 @@ public partial class MainWindow : Window //HotKey _hotKey0, _hotKey1, _hotKey2, _hotKey3, _hotKey4; public MainWindow() { + if (!Directory.Exists("Log")) + { + System.IO.Directory.CreateDirectory("Log"); + } + Form_Load(); InitializeComponent(); DataContext = Vm; diff --git a/ViewModel/ViewModelLocator.cs b/ViewModel/ViewModelLocator.cs index 8d7c189..9dd7b4b 100644 --- a/ViewModel/ViewModelLocator.cs +++ b/ViewModel/ViewModelLocator.cs @@ -14,7 +14,6 @@ using CommonServiceLocator; using GalaSoft.MvvmLight.Ioc; -using System.IO; namespace ToastFish.ViewModel { @@ -29,11 +28,6 @@ public class ViewModelLocator /// public ViewModelLocator() { - if (!Directory.Exists("Log")) - { - System.IO.Directory.CreateDirectory("Log"); - } - ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); SimpleIoc.Default.Register(); }