private void Window_Loaded(object sender, RoutedEventArgs e) { //更新配置文件 if (Properties.Settings.Default.UpgradeRequired) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.UpgradeRequired = false; Properties.Settings.Default.Save(); } //判断文件是否存在 CheckFile(); //修复设置错误 CheckSettings(); //Properties.Settings.Default.Reset(); if (!Directory.Exists(Properties.Settings.Default.BasePicPath)) { Properties.Settings.Default.BasePicPath = AppDomain.CurrentDomain.BaseDirectory + "Pic\\"; } //创建 Log文件夹 if (!Directory.Exists("log")) { Directory.CreateDirectory("log"); } //创建 ScanLog 文件夹 if (!Directory.Exists("log\\scanlog")) { Directory.CreateDirectory("log\\scanlog"); } //创建 DataBase 文件夹 if (!Directory.Exists("DataBase")) { Directory.CreateDirectory("DataBase"); } //创建备份文件夹 if (!Directory.Exists("BackUp")) { Directory.CreateDirectory("BackUp"); } SetSkin(); statusText.Text = "启动中……"; InitDataBase(); //初始化数据库 InitJav321IDConverter(); //初始化 jav321,多 30M 内存 //初始化参数 Identify.InitFanhaoList(); Scan.InitSearchPattern(); StaticVariable.InitVariable(); Net.Init(); //创建图片文件夹 if (!Directory.Exists(StaticVariable.BasePicPath + "ScreenShot\\")) { Directory.CreateDirectory(StaticVariable.BasePicPath + "ScreenShot\\"); } if (!Directory.Exists(StaticVariable.BasePicPath + "SmallPic\\")) { Directory.CreateDirectory(StaticVariable.BasePicPath + "SmallPic\\"); } if (!Directory.Exists(StaticVariable.BasePicPath + "BigPic\\")) { Directory.CreateDirectory(StaticVariable.BasePicPath + "BigPic\\"); } if (!Directory.Exists(StaticVariable.BasePicPath + "ExtraPic\\")) { Directory.CreateDirectory(StaticVariable.BasePicPath + "ExtraPic\\"); } if (!Directory.Exists(StaticVariable.BasePicPath + "Actresses\\")) { Directory.CreateDirectory(StaticVariable.BasePicPath + "Actresses\\"); } if (!Directory.Exists(StaticVariable.BasePicPath + "Gif\\")) { Directory.CreateDirectory(StaticVariable.BasePicPath + "Gif\\"); } //默认打开某个数据库 if (Properties.Settings.Default.OpenDataBaseDefault && File.Exists(Properties.Settings.Default.DataBasePath)) { OpenDefaultDatabase(); //启动主窗口 Main main = new Main(); statusText.Text = "初始化影片"; main.InitMovie(); main.Show(); this.Close(); } else { SelectDbBorder.Visibility = Visibility.Visible; } }
public async void LoadDataBase(object sender, MouseButtonEventArgs e) { //加载数据库 StackPanel stackPanel = sender as StackPanel; TextBox TextBox = stackPanel.Children[1] as TextBox; string name = TextBox.Text.ToLower(); if (name == "info") { Properties.Settings.Default.DataBasePath = AppDomain.CurrentDomain.BaseDirectory + "info.sqlite"; } else if (name == "新建视频库") { //重命名 TextBox.IsEnabled = true; TextBox.IsReadOnly = false; TextBox.Text = "我的视频"; TextBox.Focus(); TextBox.SelectAll(); TextBox.Cursor = Cursors.IBeam; return; } else { Properties.Settings.Default.DataBasePath = AppDomain.CurrentDomain.BaseDirectory + $"\\DataBase\\{name}.sqlite"; } if (!File.Exists(Properties.Settings.Default.DataBasePath)) { return; } SelectDbBorder.Visibility = Visibility.Hidden; if (Properties.Settings.Default.ScanGivenPath) { await Task.Run(() => { try { this.Dispatcher.BeginInvoke(new Action(() => { statusText.Text = $"扫描指定文件夹"; }), System.Windows.Threading.DispatcherPriority.Render); List <string> filepaths = Scan.ScanPaths(ReadScanPathFromConfig(Properties.Settings.Default.DataBasePath.Split('\\').Last().Split('.').First()), ct); Scan.DistinctMovieAndInsert(filepaths, ct); } catch (Exception ex) { Logger.LogF(ex); } }, cts.Token); } //启动主窗口 Main main = new Main(); statusText.Text = "初始化影片"; main.InitMovie(); main.Show(); this.Close(); }
public async void LoadDataBase(object sender, MouseButtonEventArgs e) { //加载数据库 StackPanel stackPanel = sender as StackPanel; TextBox TextBox = stackPanel.Children[1] as TextBox; string name = TextBox.Text; if (name?.ToLower() == "info") { Properties.Settings.Default.DataBasePath = AppDomain.CurrentDomain.BaseDirectory + "info.sqlite"; } else if (name == Jvedio.Language.Resources.NewLibrary) { //重命名 TextBox.IsReadOnly = false; TextBox.Text = Jvedio.Language.Resources.MyLibrary; TextBox.Focus(); TextBox.SelectAll(); TextBox.Cursor = Cursors.IBeam; return; } else { Properties.Settings.Default.DataBasePath = AppDomain.CurrentDomain.BaseDirectory + $"\\DataBase\\{name}.sqlite"; } if (!File.Exists(Properties.Settings.Default.DataBasePath)) { return; } SelectDbBorder.Visibility = Visibility.Hidden; if (Properties.Settings.Default.ScanGivenPath) { await Task.Run(() => { try { this.Dispatcher.BeginInvoke(new Action(() => { statusText.Text = Jvedio.Language.Resources.Status_ScanDir; }), System.Windows.Threading.DispatcherPriority.Render); List <string> filepaths = Scan.ScanPaths(ReadScanPathFromConfig(Path.GetFileNameWithoutExtension(Properties.Settings.Default.DataBasePath)), ct); Scan.InsertWithNfo(filepaths, ct); } catch (Exception ex) { Logger.LogF(ex); } }, cts.Token); } //启动主窗口 Main main = new Main(); statusText.Text = Jvedio.Language.Resources.Status_InitMovie; try { main.InitMovie(); } catch (Exception ex) { MessageBox.Show(ex.Message); Logger.LogE(ex); } main.Show(); this.Close(); }
public async void StartRun(object sender, RoutedEventArgs e) { if (Running) { HandyControl.Controls.Growl.Error(Jvedio.Language.Resources.Message_StopAndTry, "ToolsGrowl"); return; } cts = new CancellationTokenSource(); cts.Token.Register(() => { HandyControl.Controls.Growl.Info(Jvedio.Language.Resources.Message_CancelCurrentTask, "ToolsGrowl"); }); ct = cts.Token; int index = TabControl.SelectedIndex; Running = true; switch (index) { case 0: //扫描 double totalnum = 0; //扫描出的视频总数 double insertnum = 0; //导入的视频总数 try { //全盘扫描 if ((bool)ScanAll.IsChecked) { LoadingStackPanel.Visibility = Visibility.Visible; await Task.Run(() => { ct.ThrowIfCancellationRequested(); List <string> filepaths = Scan.ScanAllDrives(); totalnum = filepaths.Count; insertnum = Scan.InsertWithNfo(filepaths, ct); }); } else { if (vieModel.ScanPath.Count == 0) { break; } LoadingStackPanel.Visibility = Visibility.Visible; await Task.Run(() => { ct.ThrowIfCancellationRequested(); StringCollection stringCollection = new StringCollection(); foreach (var item in vieModel.ScanPath) { if (Directory.Exists(item)) { stringCollection.Add(item); } } List <string> filepaths = Scan.ScanPaths(stringCollection, ct); totalnum = filepaths.Count; insertnum = Scan.InsertWithNfo(filepaths, ct); }, cts.Token); } LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { HandyControl.Controls.Growl.Info($"{Jvedio.Language.Resources.Message_ScanNum} {totalnum} {Jvedio.Language.Resources.ImportNumber} {insertnum}", "ToolsGrowl"); } } catch (OperationCanceledException ex) { Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {ex.Message}"); } finally { cts.Dispose(); Running = false; } break; case 1: //Access LoadingStackPanel.Visibility = Visibility.Visible; string AccessPath = AccessPathTextBox.Text; if (!File.Exists(AccessPath)) { HandyControl.Controls.Growl.Error($"{Jvedio.Language.Resources.Message_FileNotExist} {AccessPath}", "ToolsGrowl"); break; } try { await Task.Run(() => { DataBase.InsertFromAccess(AccessPath); }); LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { HandyControl.Controls.Growl.Success(Jvedio.Language.Resources.Message_Success, "ToolsGrowl"); } } finally { cts.Dispose(); Running = false; } break; case 2: //NFO if (NFOTabControl.SelectedIndex == 0) { if (vieModel.NFOScanPath.Count == 0) { HandyControl.Controls.Growl.Warning(Jvedio.Language.Resources.Message_CanNotBeNull, "ToolsGrowl"); } } else { if (!File.Exists(NFOPathTextBox.Text)) { HandyControl.Controls.Growl.Warning($"{Jvedio.Language.Resources.Message_FileNotExist} {NFOPathTextBox.Text}", "ToolsGrowl"); } } Running = true; try { List <string> nfoFiles = new List <string>(); if (NFOTabControl.SelectedIndex == 1) { nfoFiles.Add(NFOPathTextBox.Text); } else { //扫描所有nfo文件 await Task.Run(() => { this.Dispatcher.Invoke((Action) delegate { StatusTextBlock.Visibility = Visibility.Visible; StatusTextBlock.Text = Jvedio.Language.Resources.BeginScan; }); StringCollection stringCollection = new StringCollection(); foreach (var item in vieModel.NFOScanPath) { if (Directory.Exists(item)) { stringCollection.Add(item); } } nfoFiles = Scan.ScanNFO(stringCollection, ct, (filepath) => { this.Dispatcher.Invoke((Action) delegate { StatusTextBlock.Text = filepath; }); }); }, cts.Token); } //记录日志 Logger.LogScanInfo(Environment.NewLine + $"-----【" + DateTime.Now.ToString() + $"】NFO {Jvedio.Language.Resources.Scan}-----"); Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.Scan}{Jvedio.Language.Resources.Number} => {nfoFiles.Count} "); //导入所有 nfo 文件信息 double total = 0; bool importpic = (bool)NFOCopyPicture.IsChecked; await Task.Run(() => { nfoFiles.ForEach(item => { if (File.Exists(item)) { Movie movie = GetInfoFromNfo(item); if (movie != null && !string.IsNullOrEmpty(movie.id)) { DataBase.InsertFullMovie(movie); //复制并覆盖所有图片 if (importpic) { CopyPicToPath(movie.id, item); } total += 1; Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.ImportNumber} => {item} "); } } }); }); LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.ImportNumber} {total} "); HandyControl.Controls.Growl.Success(Environment.NewLine + $"{Jvedio.Language.Resources.ImportNumber} {total} ", "ToolsGrowl"); } } finally { cts.Dispose(); Running = false; } break; case 3: //欧美扫描 if (vieModel.ScanEuPath.Count == 0) { break; } LoadingStackPanel.Visibility = Visibility.Visible; totalnum = 0; insertnum = 0; try { await Task.Run(() => { StringCollection stringCollection = new StringCollection(); foreach (var item in vieModel.ScanEuPath) { if (Directory.Exists(item)) { stringCollection.Add(item); } } List <string> filepaths = Scan.ScanPaths(stringCollection, ct); totalnum = filepaths.Count; insertnum = Scan.InsertWithNfo(filepaths, ct, IsEurope: true); }); LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { HandyControl.Controls.Growl.Info($"{Jvedio.Language.Resources.Scan}{Jvedio.Language.Resources.Number} {totalnum} {Jvedio.Language.Resources.ImportNumber} {insertnum} ", "ToolsGrowl"); } } finally { cts.Dispose(); Running = false; } break; case 4: break; case 5: //网络驱动器 LoadingStackPanel.Visibility = Visibility.Visible; string path = UNCPathTextBox.Text; if (path == "") { break; } bool CanScan = true; //检查权限 await Task.Run(() => { try { var tl = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly); } catch { CanScan = false; } }); if (!CanScan) { LoadingStackPanel.Visibility = Visibility.Hidden; HandyControl.Controls.Growl.Error(Jvedio.Language.Resources.InsufficientPermissions, "ToolsGrowl"); break; } bool IsEurope = !(bool)ScanTypeRadioButton.IsChecked; totalnum = 0; insertnum = 0; try { await Task.Run(() => { StringCollection stringCollection = new StringCollection(); stringCollection.Add(path); List <string> filepaths = Scan.ScanPaths(stringCollection, ct); totalnum = filepaths.Count; insertnum = Scan.InsertWithNfo(filepaths, ct, IsEurope: IsEurope); }); LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { HandyControl.Controls.Growl.Info($"{Jvedio.Language.Resources.Scan}{Jvedio.Language.Resources.Number} {totalnum} {Jvedio.Language.Resources.ImportNumber} {insertnum} ", "ToolsGrowl"); } } finally { cts.Dispose(); Running = false; } break; default: break; } Running = false; }
private void Window_Loaded(object sender, RoutedEventArgs e) { statusText.Text = Jvedio.Language.Resources.Status_UpdateConfig; try { if (Properties.Settings.Default.UpgradeRequired) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.UpgradeRequired = false; Properties.Settings.Default.Save(); } } catch (Exception ex) { MessageBox.Show(ex.Message); Logger.LogE(ex); } statusText.Text = Jvedio.Language.Resources.Status_RepairConfig; try { CheckFile(); //判断文件是否存在 CheckSettings(); //修复设置错误 } catch (Exception ex) { MessageBox.Show(ex.Message); Logger.LogE(ex); } if (!Directory.Exists(Properties.Settings.Default.BasePicPath)) { Properties.Settings.Default.BasePicPath = AppDomain.CurrentDomain.BaseDirectory + "Pic\\"; } statusText.Text = Jvedio.Language.Resources.Status_CreateDir; try { if (!Directory.Exists("log")) { Directory.CreateDirectory("log"); } //创建 Log文件夹 if (!Directory.Exists("log\\scanlog")) { Directory.CreateDirectory("log\\scanlog"); } //创建 ScanLog 文件夹 if (!Directory.Exists("DataBase")) { Directory.CreateDirectory("DataBase"); } //创建 DataBase 文件夹 if (!Directory.Exists("BackUp")) { Directory.CreateDirectory("BackUp"); } //创建备份文件夹 SetSkin(); } catch (Exception ex) { MessageBox.Show(ex.Message); Logger.LogE(ex); } statusText.Text = Jvedio.Language.Resources.Status_InitDatabase; try { InitDataBase();//初始化数据库 //InitJav321IDConverter(); //初始化参数 statusText.Text = Jvedio.Language.Resources.Status_InitID; Identify.InitFanhaoList(); statusText.Text = Jvedio.Language.Resources.Status_InitScan; Scan.InitSearchPattern(); InitVariable(); } catch (Exception ex) { MessageBox.Show(ex.Message); Logger.LogE(ex); } try { SaveScanPathToXml(); SaveServersToXml(); SaveRecentWatchedToXml(); } catch (Exception ex) { MessageBox.Show(ex.Message); Logger.LogE(ex); } try { statusText.Text = Jvedio.Language.Resources.Status_ClearRecentWatch; ClearDateBefore(DateTime.Now.AddDays(-10)); statusText.Text = Jvedio.Language.Resources.Status_ClearLog; ClearLogBefore(DateTime.Now.AddDays(-10), AppDomain.CurrentDomain.BaseDirectory + "log"); ClearLogBefore(DateTime.Now.AddDays(-10), AppDomain.CurrentDomain.BaseDirectory + "log\\NetWork"); ClearLogBefore(DateTime.Now.AddDays(-10), AppDomain.CurrentDomain.BaseDirectory + "log\\scanlog"); ClearLogBefore(DateTime.Now.AddDays(-10), AppDomain.CurrentDomain.BaseDirectory + "log\\file"); } catch (Exception ex) { MessageBox.Show(ex.Message); Logger.LogE(ex); } statusText.Text = Jvedio.Language.Resources.Status_InitNet; try { Net.Init(); statusText.Text = Jvedio.Language.Resources.Status_CreateDir; if (!Directory.Exists(BasePicPath + "ScreenShot\\")) { Directory.CreateDirectory(BasePicPath + "ScreenShot\\"); } if (!Directory.Exists(BasePicPath + "SmallPic\\")) { Directory.CreateDirectory(BasePicPath + "SmallPic\\"); } if (!Directory.Exists(BasePicPath + "BigPic\\")) { Directory.CreateDirectory(BasePicPath + "BigPic\\"); } if (!Directory.Exists(BasePicPath + "ExtraPic\\")) { Directory.CreateDirectory(BasePicPath + "ExtraPic\\"); } if (!Directory.Exists(BasePicPath + "Actresses\\")) { Directory.CreateDirectory(BasePicPath + "Actresses\\"); } if (!Directory.Exists(BasePicPath + "Gif\\")) { Directory.CreateDirectory(BasePicPath + "Gif\\"); } } catch (Exception ex) { MessageBox.Show(ex.Message); Logger.LogE(ex); } //默认打开某个数据库 if (Properties.Settings.Default.OpenDataBaseDefault && File.Exists(Properties.Settings.Default.DataBasePath)) { try { OpenDefaultDatabase(); } catch (Exception ex) { MessageBox.Show(ex.Message); Logger.LogE(ex); } //启动主窗口 Main main = new Main(); statusText.Text = Jvedio.Language.Resources.Status_InitMovie; try { main.InitMovie(); } catch (Exception ex) { MessageBox.Show(ex.Message); Logger.LogE(ex); } main.Show(); this.Close(); } else { SelectDbBorder.Visibility = Visibility.Visible; } }
public Movie GetInfoFromNfo(string path) { XmlDocument doc = new XmlDocument(); try { doc.Load(path); } catch { return(null); } XmlNode rootNode = doc.SelectSingleNode("movie"); if (rootNode == null) { return(null); } Movie movie = new Movie(); foreach (XmlNode node in rootNode.ChildNodes) { try { switch (node.Name) { case "id": movie.id = node.InnerText.ToUpper(); break; case "title": movie.title = node.InnerText; break; case "release": movie.releasedate = node.InnerText; break; case "director": movie.director = node.InnerText; break; case "studio": movie.studio = node.InnerText; break; case "rating": movie.rating = node.InnerText == "" ? 0 : float.Parse(node.InnerText); break; case "plot": movie.plot = node.InnerText; break; case "outline": movie.outline = node.InnerText; break; case "year": movie.year = node.InnerText == "" ? 1970 : int.Parse(node.InnerText); break; case "runtime": movie.runtime = node.InnerText == "" ? 0 : int.Parse(node.InnerText); break; case "country": movie.country = node.InnerText; break; case "source": movie.sourceurl = node.InnerText; break; default: break; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.Message); continue; } } if (movie.id == "") { return(null); } //视频类型 movie.vediotype = (int)Identify.GetVedioType(movie.id); //扫描视频获得文件大小 if (File.Exists(path)) { string fatherpath = new FileInfo(path).DirectoryName; string[] files = null; try { files = Directory.GetFiles(fatherpath, "*.*", SearchOption.TopDirectoryOnly); } catch (Exception e) { Logger.LogE(e); } if (files != null) { var movielist = Scan.FirstFilter(files.ToList(), movie.id); if (movielist.Count == 1) { movie.filepath = movielist[0]; } else if (movielist.Count > 1) { //分段视频 movie.filepath = movielist[0]; string subsection = ""; movielist.ForEach(arg => { subsection += arg + ";"; }); movie.subsection = subsection; } } } //tag XmlNodeList tagNodes = doc.SelectNodes("/movie/tag"); if (tagNodes != null) { string tags = ""; foreach (XmlNode item in tagNodes) { if (item.InnerText != "") { tags += item.InnerText + " "; } } if (tags.Length > 0) { if (movie.id.IndexOf("FC2") >= 0) { movie.genre = tags.Substring(0, tags.Length - 1); } else { movie.tag = tags.Substring(0, tags.Length - 1); } } } //genre XmlNodeList genreNodes = doc.SelectNodes("/movie/genre"); if (genreNodes != null) { string genres = ""; foreach (XmlNode item in genreNodes) { if (item.InnerText != "") { genres += item.InnerText + " "; } } if (genres.Length > 0) { movie.genre = genres.Substring(0, genres.Length - 1); } } //actor XmlNodeList actorNodes = doc.SelectNodes("/movie/actor/name"); if (actorNodes != null) { string actors = ""; foreach (XmlNode item in actorNodes) { if (item.InnerText != "") { actors += item.InnerText + " "; } } if (actors.Length > 0) { movie.actor = actors.Substring(0, actors.Length - 1); } } //fanart XmlNodeList fanartNodes = doc.SelectNodes("/movie/fanart/thumb"); if (fanartNodes != null) { string extraimageurl = ""; foreach (XmlNode item in fanartNodes) { if (item.InnerText != "") { extraimageurl += item.InnerText + ";"; } } if (extraimageurl.Length > 0) { movie.extraimageurl = extraimageurl.Substring(0, extraimageurl.Length - 1); } } return(movie); }
public async void StartRun(object sender, RoutedEventArgs e) { if (Running) { HandyControl.Controls.Growl.Error("其他任务正在进行!", "ToolsGrowl"); return; } cts = new CancellationTokenSource(); cts.Token.Register(() => { HandyControl.Controls.Growl.Info("取消当前下载任务!", "ToolsGrowl"); }); ct = cts.Token; var grids = MainGrid.Children.OfType <Grid>().ToList(); int index = 0; for (int i = 0; i < grids.Count; i++) { if (grids[i].Visibility == Visibility.Visible) { index = i; break; } } Running = true; switch (index) { case 0: //扫描 double totalnum = 0; //扫描出的视频总数 double insertnum = 0; //导入的视频总数 try { //全盘扫描 if ((bool)ScanAll.IsChecked) { LoadingStackPanel.Visibility = Visibility.Visible; await Task.Run(() => { ct.ThrowIfCancellationRequested(); List <string> filepaths = Scan.ScanAllDrives(); totalnum = filepaths.Count; insertnum = Scan.DistinctMovieAndInsert(filepaths, ct); }); } else { if (vieModel.ScanPath.Count == 0) { break; } LoadingStackPanel.Visibility = Visibility.Visible; await Task.Run(() => { ct.ThrowIfCancellationRequested(); StringCollection stringCollection = new StringCollection(); foreach (var item in vieModel.ScanPath) { if (Directory.Exists(item)) { stringCollection.Add(item); } } List <string> filepaths = Scan.ScanPaths(stringCollection, ct); totalnum = filepaths.Count; insertnum = Scan.DistinctMovieAndInsert(filepaths, ct); }, cts.Token); } LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { HandyControl.Controls.Growl.Info($"扫描出 {totalnum} 个,导入 {insertnum} 个", "ToolsGrowl"); } } catch (OperationCanceledException ex) { Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {ex.Message}"); } finally { cts.Dispose(); Running = false; } break; case 1: //Access LoadingStackPanel.Visibility = Visibility.Visible; string AccessPath = AccessPathTextBox.Text; if (!File.Exists(AccessPath)) { HandyControl.Controls.Growl.Error($"不存在 :{AccessPath}", "ToolsGrowl"); break; } try { await Task.Run(() => { DataBase.InsertFromAccess(AccessPath); }); LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { HandyControl.Controls.Growl.Success("成功!", "ToolsGrowl"); } } finally { cts.Dispose(); Running = false; } break; case 2: //NFO if ((bool)NfoRB1.IsChecked) { if (vieModel.NFOScanPath.Count == 0) { HandyControl.Controls.Growl.Warning("路径为空!", "ToolsGrowl"); } } else { if (!File.Exists(NFOPathTextBox.Text)) { HandyControl.Controls.Growl.Warning($"文件不存在{NFOPathTextBox.Text}", "ToolsGrowl"); } } Running = true; try { List <string> nfoFiles = new List <string>(); if (!(bool)NfoRB1.IsChecked) { nfoFiles.Add(NFOPathTextBox.Text); } else { //扫描所有nfo文件 await Task.Run(() => { this.Dispatcher.Invoke((Action) delegate { StatusTextBlock.Visibility = Visibility.Visible; StatusTextBlock.Text = "开始扫描"; }); StringCollection stringCollection = new StringCollection(); foreach (var item in vieModel.NFOScanPath) { if (Directory.Exists(item)) { stringCollection.Add(item); } } nfoFiles = Scan.ScanNFO(stringCollection, ct, (filepath) => { this.Dispatcher.Invoke((Action) delegate { StatusTextBlock.Text = filepath; }); }); }, cts.Token); } //记录日志 Logger.LogScanInfo("\n-----【" + DateTime.Now.ToString() + "】NFO扫描-----"); Logger.LogScanInfo($"\n扫描出 => {nfoFiles.Count} 个 "); //导入所有 nfo 文件信息 double total = 0; bool importpic = (bool)NFOCopyPicture.IsChecked; await Task.Run(() => { nfoFiles.ForEach(item => { if (File.Exists(item)) { Movie movie = GetInfoFromNfo(item); if (movie != null && !string.IsNullOrEmpty(movie.id)) { DataBase.InsertFullMovie(movie); //复制并覆盖所有图片 if (importpic) { CopyPicToPath(movie.id, item); } total += 1; Logger.LogScanInfo($"\n成功导入数据库 => {item} "); } } }); }); LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { Logger.LogScanInfo($"\n成功导入 {total} 个"); HandyControl.Controls.Growl.Success($"\n成功导入 {total} 个", "ToolsGrowl"); } } finally { cts.Dispose(); Running = false; } break; case 3: //欧美扫描 if (vieModel.ScanEuPath.Count == 0) { break; } LoadingStackPanel.Visibility = Visibility.Visible; totalnum = 0; insertnum = 0; try { await Task.Run(() => { StringCollection stringCollection = new StringCollection(); foreach (var item in vieModel.ScanEuPath) { if (Directory.Exists(item)) { stringCollection.Add(item); } } List <string> filepaths = Scan.ScanPaths(stringCollection, ct); totalnum = filepaths.Count; insertnum = Scan.DistinctMovieAndInsert(filepaths, ct, true); }); LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { HandyControl.Controls.Growl.Info($"扫描出 {totalnum} 个,导入 {insertnum} 个"); } } finally { cts.Dispose(); Running = false; } break; case 4: break; case 5: //网络驱动器 LoadingStackPanel.Visibility = Visibility.Visible; string path = UNCPathTextBox.Text; if (path == "") { break; } bool CanScan = true; //检查权限 await Task.Run(() => { try { var tl = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly); } catch { CanScan = false; } }); if (!CanScan) { LoadingStackPanel.Visibility = Visibility.Hidden; HandyControl.Controls.Growl.Error($"权限不够!"); break; } bool IsEurope = (bool)ScanTypeRadioButton.IsChecked ? false : true; totalnum = 0; insertnum = 0; try { await Task.Run(() => { StringCollection stringCollection = new StringCollection(); stringCollection.Add(path); List <string> filepaths = Scan.ScanPaths(stringCollection, ct); totalnum = filepaths.Count; insertnum = Scan.DistinctMovieAndInsert(filepaths, ct, IsEurope); }); LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { HandyControl.Controls.Growl.Info($"扫描出 {totalnum} 个,导入 {insertnum} 个"); } } finally { cts.Dispose(); Running = false; } break; default: break; } Running = false; }
public static double InsertWithNfo(List <string> filepaths, CancellationToken ct, Action <string> messageCallBack = null, bool IsEurope = false) { List <string> nfopaths = new List <string>(); List <string> vediopaths = new List <string>(); foreach (var item in filepaths) { if (item.ToLower().EndsWith(".nfo")) { nfopaths.Add(item); } else { vediopaths.Add(item); } } //先导入 nfo 再导入视频,避免路径覆盖 if (nfopaths.Count > 0 && Properties.Settings.Default.ScanNfo) { Logger.LogScanInfo(Environment.NewLine + "-----【" + DateTime.Now.ToString() + "】-----"); Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.ScanNFO} => {nfopaths.Count} " + Environment.NewLine); double total = 0; //导入 nfo 文件 nfopaths.ForEach(item => { if (File.Exists(item)) { Movie movie = FileProcess.GetInfoFromNfo(item); if (movie != null && !string.IsNullOrEmpty(movie.id)) { DataBase.InsertFullMovie(movie); total += 1; Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.SuccessImportToDataBase} => {item} "); } } }); Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.ImportNFONumber}: {total}" + Environment.NewLine); messageCallBack?.Invoke($"{Jvedio.Language.Resources.ImportNFONumber}: {total}"); } //导入视频 if (vediopaths.Count > 0) { try { double _num = Scan.DistinctMovieAndInsert(vediopaths, ct, IsEurope); messageCallBack?.Invoke($"{Jvedio.Language.Resources.ImportVideioNumber}:{_num},详情请看日志"); return(_num); }catch (OperationCanceledException ex) { Logger.LogF(ex); messageCallBack?.Invoke($"{Jvedio.Language.Resources.Cancel}"); } } return(0); }
private async void Window_Loaded(object sender, RoutedEventArgs e) { //判断文件是否存在 CheckFile(); //修复设置错误 CheckSettings(); //Properties.Settings.Default.Reset(); if (!Directory.Exists(Properties.Settings.Default.BasePicPath)) { Properties.Settings.Default.BasePicPath = AppDomain.CurrentDomain.BaseDirectory + "Pic\\"; } //创建 Log文件夹 if (!Directory.Exists("log")) { Directory.CreateDirectory("log"); } //创建 ScanLog 文件夹 if (!Directory.Exists("log\\scanlog")) { Directory.CreateDirectory("log\\scanlog"); } //创建 DataBase 文件夹 if (!Directory.Exists("DataBase")) { Directory.CreateDirectory("DataBase"); } //创建备份文件夹 if (!Directory.Exists("BackUp")) { Directory.CreateDirectory("BackUp"); } SetSkin(); //初始化数据库 InitDataBase(); statusText.Text = "启动中……"; //初始化参数 Identify.InitFanhaoList(); Scan.InitSearchPattern(); StaticVariable.InitVariable(); //创建图片文件夹 if (!Directory.Exists(StaticVariable.BasePicPath + "ScreenShot\\")) { Directory.CreateDirectory(StaticVariable.BasePicPath + "ScreenShot\\"); } if (!Directory.Exists(StaticVariable.BasePicPath + "SmallPic\\")) { Directory.CreateDirectory(StaticVariable.BasePicPath + "SmallPic\\"); } if (!Directory.Exists(StaticVariable.BasePicPath + "BigPic\\")) { Directory.CreateDirectory(StaticVariable.BasePicPath + "BigPic\\"); } if (!Directory.Exists(StaticVariable.BasePicPath + "ExtraPic\\")) { Directory.CreateDirectory(StaticVariable.BasePicPath + "ExtraPic\\"); } if (!Directory.Exists(StaticVariable.BasePicPath + "Actresses\\")) { Directory.CreateDirectory(StaticVariable.BasePicPath + "Actresses\\"); } //输入密码 //DialogInput dialogInput = new DialogInput(this,"请输入密码", "123"); //if (dialogInput .ShowDialog()== false) { this.Close(); } else //{ // string password = dialogInput.Text; // if (password != "123") // { // this.Close(); // } //} if (Properties.Settings.Default.OpenDataBaseDefault) { if (Properties.Settings.Default.ScanGivenPath) { await Task.Run(() => { this.Dispatcher.BeginInvoke(new Action(() => { statusText.Text = $"扫描指定文件夹"; }), System.Windows.Threading.DispatcherPriority.Render); List <string> filepaths = Scan.ScanPaths(ReadScanPathFromConfig(Properties.Settings.Default.DataBasePath.Split('\\').Last().Split('.').First()), ct); DataBase cdb = new DataBase(); Scan.DistinctMovieAndInsert(filepaths, ct); }, cts.Token); } //启动主窗口 Main main = new Main(); statusText.Text = "初始化影片"; main.InitMovie(); main.Show(); this.Close(); } else { SelectDbBorder.Visibility = Visibility.Visible; } }