// -------------------------------------------------------------------- // 検出ファイルリストテーブルにファイル情報を追加 // AddFileNames() で追加されない情報をすべて付与する // ファイルは再帰検索しない // -------------------------------------------------------------------- private static void AddInfosCore(TargetFolderInfo targetFolderInfo) { // フォルダー設定を読み込む FolderSettingsInDisk folderSettingsInDisk = YlCommon.LoadFolderSettings(targetFolderInfo.TargetPath); FolderSettingsInMemory folderSettingsInMemory = YlCommon.CreateFolderSettingsInMemory(folderSettingsInDisk); using ListContextInMemory listContextInMemory = new(); using TFoundSetter foundSetter = new(listContextInMemory); // 指定フォルダーの全レコード IQueryable <TFound> targetRecords = listContextInMemory.Founds.Where(x => x.Folder == targetFolderInfo.TargetPath); // 情報付与 foreach (TFound record in targetRecords) { FileInfo fileInfo = new(record.Path); record.LastWriteTime = JulianDay.DateTimeToModifiedJulianDate(fileInfo.LastWriteTime); record.FileSize = fileInfo.Length; foundSetter.SetTFoundValues(record, folderSettingsInMemory); YlModel.Instance.EnvModel.AppCancellationTokenSource.Token.ThrowIfCancellationRequested(); } AddFolderTagsInfo(targetFolderInfo, targetRecords, listContextInMemory.Tags, listContextInMemory.TagSequences); // コミット listContextInMemory.SaveChanges(); }
// -------------------------------------------------------------------- // 過去の統計を更新 // -------------------------------------------------------------------- private void UpdatePast() { Debug.WriteLine("UpdatePast()"); using YukariStatisticsContext yukariStatisticsContext = new(); IQueryable <TYukariStatistics> targetYukariStatistics = yukariStatisticsContext.YukariStatistics.Where(x => (UpdatePastYukariStatisticsKind == UpdatePastYukariStatisticsKind.All || !x.AttributesDone) && !x.Invalid); foreach (TYukariStatistics oneStatistics in targetYukariStatistics) { #if DEBUGz if (oneStatistics.RequestMoviePath == @"D:\TempD\TestNkl\TST9_楽曲情報編集\テストタイアップ1_テスト楽曲101_ファイル歌手1,初音ミク.mp4") { } #endif if (!File.Exists(oneStatistics.RequestMoviePath)) { continue; } String requestMovieFolder = Path.GetDirectoryName(oneStatistics.RequestMoviePath) ?? String.Empty; if (YlCommon.FindSettingsFolder(requestMovieFolder) == null) { continue; } Debug.WriteLine("UpdatePast() 設定:" + oneStatistics.RequestMoviePath); // TFound 下準備 FileInfo fileInfo = new(oneStatistics.RequestMoviePath); TFound found = new() { Path = oneStatistics.RequestMoviePath, Folder = requestMovieFolder, ParentFolder = requestMovieFolder, LastWriteTime = JulianDay.DateTimeToModifiedJulianDate(fileInfo.LastWriteTime), FileSize = fileInfo.Length, }; // フォルダー設定を読み込む FolderSettingsInDisk folderSettingsInDisk = YlCommon.LoadFolderSettings(found.Folder); FolderSettingsInMemory folderSettingsInMemory = YlCommon.CreateFolderSettingsInMemory(folderSettingsInDisk); using ListContextInMemory listContextInMemory = new(); using TFoundSetter foundSetter = new(listContextInMemory); // TFound 設定 foundSetter.SetTFoundValues(found, folderSettingsInMemory); // 統計設定 DbCommon.CopyFoundToYukariStatisticsIfAttributesPrepared(found, oneStatistics); } yukariStatisticsContext.SaveChanges(); UpdatePastYukariStatisticsKind = UpdatePastYukariStatisticsKind.None; }
// -------------------------------------------------------------------- // イベントハンドラー:プレブス一覧の編集ボタンがクリックされた // -------------------------------------------------------------------- private void ButtonEditInfoClicked(Int32 oRowIndex) { // ファイル命名規則とフォルダー固定値を適用 FolderSettingsInDisk aFolderSettingsInDisk = NklCommon.LoadFolderSettings(mFolder); FolderSettingsInMemory aFolderSettingsInMemory = NklCommon.CreateFolderSettingsInMemory(aFolderSettingsInDisk); Dictionary <String, String> aDic = NklCommon.MatchFileNameRulesAndFolderRule (Path.GetFileNameWithoutExtension((String)DataGridViewPreview.Rows[oRowIndex].Cells[(Int32)PreviewColumns.File].Value), aFolderSettingsInMemory); // 楽曲名が取得できていない場合は編集不可 if (String.IsNullOrEmpty(aDic[NklCommon.RULE_VAR_TITLE])) { ShowLogMessage(TraceEventType.Error, "ファイル名から楽曲名を取得できていないため、編集できません。\nファイル命名規則を確認して下さい。"); return; } using (FormEditInfo aFormEditInfo = new FormEditInfo(aDic, mNicoKaraListerSettings, mLogWriter)) { aFormEditInfo.ShowDialog(this); } }
// -------------------------------------------------------------------- // データグリッドビューを更新 // -------------------------------------------------------------------- private void UpdateDataGridViewPreview(Object oDummy) { try { // 準備 DisableComponents(); SetCursor(Cursors.WaitCursor); Invoke(new Action(() => { // クリア DataGridViewPreview.Rows.Clear(); // 検索 String[] aAllPathes = Directory.GetFiles(mFolder); // マッチをリストに追加 FolderSettingsInDisk aFolderSettingsInDisk = NklCommon.LoadFolderSettings(mFolder); FolderSettingsInMemory aFolderSettingsInMemory = NklCommon.CreateFolderSettingsInMemory(aFolderSettingsInDisk); Dictionary <String, String> aRuleMap = NklCommon.CreateRuleDictionaryWithDescription(); foreach (String aPath in aAllPathes) { if (!mOutputSettings.TargetExts.Contains(Path.GetExtension(aPath).ToLower())) { continue; } // ファイル命名規則とフォルダー固定値を適用 Dictionary <String, String> aDic = NklCommon.MatchFileNameRulesAndFolderRule(Path.GetFileNameWithoutExtension(aPath), aFolderSettingsInMemory); // DGV 追加 DataGridViewPreview.Rows.Add(); Int32 aIndex = DataGridViewPreview.Rows.Count - 1; // ファイル DataGridViewPreview.Rows[aIndex].Cells[(Int32)PreviewColumns.File].Value = Path.GetFileName(aPath); // 項目と値 StringBuilder aSB = new StringBuilder(); foreach (KeyValuePair <String, String> aKvp in aDic) { if (aKvp.Key != NklCommon.RULE_VAR_ANY && !String.IsNullOrEmpty(aKvp.Value)) { aSB.Append(aRuleMap[aKvp.Key] + "=" + aKvp.Value + ", "); } } DataGridViewPreview.Rows[aIndex].Cells[(Int32)PreviewColumns.Matches].Value = aSB.ToString(); // 編集 DataGridViewPreview.Rows[aIndex].Cells[(Int32)PreviewColumns.Edit].Value = "編集"; } // 選択解除 DataGridViewPreview.ClearSelection(); // 次の編集候補ボタン UpdateButtonJump(); })); } catch (OperationCanceledException) { ShowLogMessage(Common.TRACE_EVENT_TYPE_STATUS, "ファイル検索結果更新を中止しました。"); } catch (Exception oExcep) { ShowLogMessage(TraceEventType.Error, "ファイル検索結果更新更新時エラー:\n" + oExcep.Message); ShowLogMessage(TraceEventType.Verbose, " スタックトレース:\n" + oExcep.StackTrace); } finally { // 後片付け SetCursor(Cursors.Default); EnableComponents(); } }
// -------------------------------------------------------------------- // 編集する必要がありそうなファイルに飛ぶ // -------------------------------------------------------------------- private void JumpToNextCandidate(Object oDummy) { try { // 準備 DisableComponents(); SetCursor(Cursors.WaitCursor); // 初めての場合は CSV をロード if (mProgramCsvs == null) { NklCommon.LoadCsvs(mNicoKaraListerSettings, out mProgramCsvs, out mSongCsvs, out mProgramAliasCsvs, out mSongAliasCsvs); } Invoke(new Action(() => { Int32 aRowIndex = -1; if (DataGridViewPreview.SelectedRows.Count > 0) { aRowIndex = DataGridViewPreview.SelectedRows[0].Index; } // マッチ準備 FolderSettingsInDisk aFolderSettingsInDisk = NklCommon.LoadFolderSettings(mFolder); FolderSettingsInMemory aFolderSettingsInMemory = NklCommon.CreateFolderSettingsInMemory(aFolderSettingsInDisk); for (; ;) { aRowIndex++; if (aRowIndex >= DataGridViewPreview.RowCount) { ShowLogMessage(TraceEventType.Information, "ファイル名から取得した情報が楽曲情報・番組情報に未登録のファイルは見つかりませんでした。"); DataGridViewPreview.ClearSelection(); return; } // ファイル命名規則とフォルダー固定値を適用 Dictionary <String, String> aDic = NklCommon.MatchFileNameRulesAndFolderRule( Path.GetFileNameWithoutExtension((String)DataGridViewPreview.Rows[aRowIndex].Cells[(Int32)PreviewColumns.File].Value), aFolderSettingsInMemory); // 楽曲名が空かどうか if (String.IsNullOrEmpty(aDic[NklCommon.RULE_VAR_TITLE])) { break; } // 楽曲名が anison.info と不一致かどうか String aSongOrigin = SongOriginCsv(aDic[NklCommon.RULE_VAR_TITLE]); List <String> aSongCsvRecord = NklCommon.FindCsvRecord(mSongCsvs, (Int32)SongCsvColumns.Name, aSongOrigin); if (aSongCsvRecord == null) { break; } // 番組名がある場合、番組名が anison.info と不一致かどうか if (!String.IsNullOrEmpty(aDic[NklCommon.RULE_VAR_PROGRAM])) { String aProgramOrigin = ProgramOriginCsv(aDic[NklCommon.RULE_VAR_PROGRAM]); List <String> aProgramCsvRecord = NklCommon.FindCsvRecord(mProgramCsvs, (Int32)ProgramCsvColumns.Name, aProgramOrigin); if (aProgramCsvRecord == null) { break; } } } DataGridViewPreview.Rows[aRowIndex].Selected = true; // 検出行が完全に表示されていない場合はスクロールする Int32 aBeforeRowIndex = aRowIndex > 0 ? aRowIndex - 1 : aRowIndex; Int32 aAfterRowIndex = aRowIndex < DataGridViewPreview.RowCount - 1 ? aRowIndex + 1 : aRowIndex; if (!DataGridViewPreview.Rows[aBeforeRowIndex].Displayed || !DataGridViewPreview.Rows[aAfterRowIndex].Displayed) { DataGridViewPreview.FirstDisplayedScrollingRowIndex = aRowIndex; } })); } catch (OperationCanceledException) { ShowLogMessage(Common.TRACE_EVENT_TYPE_STATUS, "未登録検出を中止しました。"); } catch (Exception oExcep) { ShowLogMessage(TraceEventType.Error, "未登録検出時エラー:\n" + oExcep.Message); ShowLogMessage(TraceEventType.Verbose, " スタックトレース:\n" + oExcep.StackTrace); } finally { // 後片付け SetCursor(Cursors.Default); EnableComponents(); } }