using Common.system; using System; using System.Threading; using System.Windows; using System.Windows.Forms; using System.Windows.Input; using XHWK.Model; using XHWK.WKTool.Skin; namespace XHWK.WKTool { /// /// 创建微课 /// public partial class CreateAMicroLessonWindow : Window { #region 字段 private FolderBrowserDialog ofd; private DialogResult result; #endregion /// /// 创建微课 /// public CreateAMicroLessonWindow() { InitializeComponent(); ResizeMode = ResizeMode.NoResize; new Thread(o => { if (!FileToolsCommon.IsExistDirectory(FileToolsCommon.GetFileAbsolutePath("/ffmpeg/"))) { try { //根据系统解压ffmpeg if (Environment.Is64BitOperatingSystem) { //64 ZipHelper.UnZip(FileToolsCommon.GetFileAbsolutePath("/ffmpegx64.zip"), FileToolsCommon.GetFileAbsolutePath()); } else { //32 ZipHelper.UnZip(FileToolsCommon.GetFileAbsolutePath("/ffmpegx32.zip"), FileToolsCommon.GetFileAbsolutePath()); } } catch (Exception) { ZipHelper.UnZip(FileToolsCommon.GetFileAbsolutePath("/ffmpegx64.zip"), FileToolsCommon.GetFileAbsolutePath()); } } }).Start(); if (!APP.CheckScreenCapturerRecorder()) { MessageWindow.Show("首次运行需安装环境,请在确定后依次点击“English-OK-Next>-Next>Install”完成安装!"); APP.InstallScreenCapturerRecorder(); } txbStoragePath.Text = FileToolsCommon.GetConfigValue("VideoSavePath"); //APP.FFmpeg.GetMToFFmpeg(); LoadingCarouseImg(); } #region 轮播图 /// /// 图片宽度,每次切换的宽度 /// double ImgWidth = 502.00; /// /// 轮播时移动增加的宽度 /// double ImgMove = 1; /// /// 当前展示的图片序号Index从0开始 /// int ImgNumIndex = 0; /// /// 加载录播图 /// void LoadingCarouseImg() { new Thread(new ThreadStart(new Action(() => { Thread.Sleep(3000); Dispatcher.Invoke(() => { ImgWidth = ImgCarouse1.ActualWidth; ImgMove = ImgWidth / 250.00; CarouseImg(); //timesCarouse = new System.Timers.Timer(2000); //timesCarouse.Elapsed += TimesCarouse_Elapsed; ; //timesCarouse.Start(); }); }))).Start(); } /// /// 轮播图 /// void CarouseImg() { new Thread(new ThreadStart(new Action(() => { while(true) { for (double i = ImgMove; i < ImgWidth; i += ImgMove) { Dispatcher.Invoke(() => { if (Math.Abs(i + ImgMove) < ImgWidth) { //图片移动轮播 SplCarouse.Margin = new Thickness(SplCarouse.Margin.Left - ImgMove, 0, 0, 0); } else { if (ImgNumIndex >= 2) { ImgNumIndex = 0; SplCarouse.Margin = new Thickness(0, 0, 0, 0); } else { ImgNumIndex++; SplCarouse.Margin = new Thickness(-(ImgNumIndex * ImgWidth), 0, 0, 0); } } }); Thread.Sleep(3); } bool IsBreak = false; Dispatcher.Invoke(() => { if (this.Visibility != Visibility.Visible) { SplCarouse.Margin = new Thickness(0); IsBreak = true; } }); Thread.Sleep(5000); if (IsBreak) { break; } } }))).Start(); } /// /// 轮播图切换 /// /// /// private void TimesCarouse_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //SplCarouse //ImgCarouse1 } #endregion #region 事件 /// /// 关闭 /// /// /// private void BtnDown_Click(object sender, RoutedEventArgs e) { MessageBoxResult dr = MessageWindow.Show("确定退出系统?", "提示", MessageBoxButton.OKCancel); if (dr == MessageBoxResult.OK) { System.Environment.Exit(0); } else { return; } } /// /// 浏览 /// /// /// private void BtnBrowse_Click(object sender, RoutedEventArgs e) { //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); ofd = new FolderBrowserDialog(); result = ofd.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { if (ofd.SelectedPath != "") { txbStoragePath.Text = ofd.SelectedPath; //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt"; //string temp = ofd.SelectedPath; //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default); } } } bool IsPressButton = false; /// /// 开始 /// /// /// private void BtnStart_Click(object sender, RoutedEventArgs e) { #region 防止连击 if (IsPressButton) { return; } else { IsPressButton = true; new Thread(new ThreadStart(new Action(() => { Thread.Sleep(500); IsPressButton = false; }))).Start(); } #endregion #region 合法性判断 if (string.IsNullOrWhiteSpace(txbExplainName.Text.Trim())) { MessageWindow.Show("讲解名称不可为空!"); return; } if (string.IsNullOrWhiteSpace(txbStoragePath.Text.Trim())) { MessageWindow.Show("路径不可为空!"); return; } try { FileToolsCommon.CreateDirectory(txbStoragePath.Text.Trim()); } catch (Exception ex) { MessageWindow.Show("路径无法访问,解决方案:\r\n1,检查路径是否可访问。\r\n2,关闭杀毒软件或信任软件。"); return; } #endregion LblCreate.Visibility = Visibility.Visible; string wkpath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + txbExplainName.Text.Trim() + "/"; string StoragePath = txbStoragePath.Text; new Thread(new ThreadStart(new Action(() => { //读取微课数据 APP.ReadWkData(wkpath); if (APP.WKData == null) { Dispatcher.Invoke(() => { APP.WKData = new Model.Model_WKData { WkPath = wkpath, WkName = txbExplainName.Text, WkCreateDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; }); } //创建文件夹 FileToolsCommon.CreateDirectory(APP.WKData.WkPath); FileToolsCommon.DeleteDirectory(wkpath + "temp"); FileToolsCommon.DeleteDirectory(wkpath + "temprs"); //存储文件 FileToolsCommon.SetConfigValue("VideoSavePath", StoragePath); APP.ReadDrawData(); #region 微课不允许有多个视频 废弃 ////判断微课是否存在,存在则询问 //if (APP.WKDataList != null&& APP.WKDataList.Count>0) //{ // if (APP.WKDataList.Exists(x => x.WkName == APP.WKData.WkName)) // { // MessageBoxResult dr = MessageWindow.Show("此微课已存在是否覆盖?", "提示", MessageBoxButton.OKCancel); // if (dr == MessageBoxResult.OK) // { // FileToolsCommon.DeleteDirectory(APP.WKData.WkPath); // FileToolsCommon.CreateDirectory(APP.WKData.WkPath); // APP.WKDataList.RemoveAll(x => x.WkName == APP.WKData.WkName); // } // else // { // return; // } // } //} #endregion Dispatcher.Invoke(() => { if (APP.W_XHMicroLessonSystemWindow == null) { //double proportion = 1036.0 / 1276.0; APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow(); //APP.W_XHMicroLessonSystemWindow.Width = proportion * (PrimaryScreen.ScaleScreenSize().Height-40); //APP.W_XHMicroLessonSystemWindow.Height =/*1276-*/ PrimaryScreen.ScaleScreenSize().Height-40; //APP.W_XHMicroLessonSystemWindow .Topmost = true; } APP.W_XHMicroLessonSystemWindow.Show(); LblCreate.Visibility = Visibility.Hidden; Hide(); }); }))).Start(); } private double screeHeight = SystemParameters.FullPrimaryScreenHeight; private double screeWidth = SystemParameters.FullPrimaryScreenWidth; /// /// 窗体移动 /// /// /// private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DragMove(); } #endregion /// /// 检测APP更新 /// private void getNewApp() { new Thread(o => { //读取本地 APP.ReadServiceAddressData(); int versionThis = int.Parse(FileToolsCommon.GetConfigValue("VersionCode")); if (versionThis < 0) { //软件是否更新,版本号小于0不更新 return; } string url = APP.apiUrl + "/apprecord/get_new"; string result = HttpHelper.PostAndRespStr(url, "{}"); Model.ResultVo resultObj = JsonHelper.JsonToObj>(result); if (result != null && resultObj.code == 0) { if (resultObj.obj != null) { try { int versionCode = resultObj.obj.versioncode; if (versionThis < versionCode) { Dispatcher.Invoke(new Action(() => { string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\"; FileToolsCommon.CreateDirectory(pathTemp); appUpdateShow(resultObj.obj); })); } } catch (Exception ex) { LogHelper.WriteErrLog("【检查更新】(getNewApp)版本号错误:" + ex.Message, ex); } } } }).Start(); } /// /// 应用更新 /// /// private void appUpdateShow(Model_App app) { AppUpdateWin win = new AppUpdateWin(app) { Topmost = true, Owner = this }; win.ShowDialog(); } private void Window_Loaded(object sender, RoutedEventArgs e) { getNewApp(); } } }