Example #1
0
        /// <summary>
        /// 選択されているスコアデータを編集する。
        /// </summary>
        private void ScoreDataEdit()
        {
            // Get selected item
            ScoreResult scoreResult = null;
            int         selectedRow = 0;

            // Get selected row
            foreach (DataGridViewCell cell in ScoreDataGridView.SelectedCells)
            {
                selectedRow = cell.RowIndex;
                scoreResult = (ScoreResult)ScoreDataGridView.Rows[selectedRow].DataBoundItem;
                break;
            }

            // If can't selected, no action
            if (scoreResult == null)
            {
                return;
            }

            // Load id and open window
            int?musicId = GetTreeViewSelectedMusicId();

            // If can't get music id, no action
            if (musicId == null)
            {
                return;
            }

            // Get music object from Music ID
            MusicDao musicDao = new MusicDao(databaseFilePath);
            Music    music    = musicDao.selectByMusicId(musicId);

            music.scoreResultList = new List <ScoreResult>();
            music.scoreResultList.Add(scoreResult);

            using (RegistScoreConfirmForm registScoreConfirmForm = new RegistScoreConfirmForm(ref music, ref music))
            {
                if (DialogResult.OK == registScoreConfirmForm.ShowDialog())
                {
                    // Regist data
                    musicDao.InsertOrReplace(music);

                    // Reflesh view
                    RefreshScoreDataGridView();

                    MessageBox.Show("スコアデータの修正が完了しました。");
                }
                else
                {
                    // cancel
                    return;
                }
            }
        }
Example #2
0
        /// <summary>
        /// 特定フォルダ内の画像に対して解析を行う。
        /// </summary>
        /// <param name="analyzeAllFile">true:全ファイルを解析、false:既に解析済みファイルがあればスキップ</param>
        private void AnalyzeScoreFromDirectory(bool analyzeAllFile)
        {
            logger.Info("Analyze score start. Analyze all file flag = " + analyzeAllFile);

            // Select target folder
            string selectedPath;

            using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
            {
                folderBrowserDialog.SelectedPath = System.Windows.Forms.Application.StartupPath;

                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    selectedPath = folderBrowserDialog.SelectedPath;
                    logger.Info("Selected folder = " + selectedPath);
                }
                else
                {
                    return;
                }
            };

            // Collect file list
            IEnumerable <string> screenshotFilePathList = Directory.EnumerateFiles(selectedPath);

            logger.Info("Target file list ... ");
            foreach (string filePath in screenshotFilePathList)
            {
                logger.Info(filePath);
            }
            logger.Info(string.Empty);

            // Parse and get music infos
            logger.Info("Analyze start.");

            StringBuilder resultStringBuilder = new StringBuilder();
            MusicDao      musicDao            = new MusicDao(databaseFilePath);

            foreach (string filePath in screenshotFilePathList)
            {
                logger.Info("Analyze target file = " + filePath);
                Music analyzedMusic = BndrImageReader.AnalyzeBndrImage(setting, filePath, dataFolderPath, analyzeAllFile);

                // If skip regist, goto next loop
                if (analyzedMusic == null)
                {
                    logger.Info("Regist music skipped, goto next file.");
                    continue;
                }

                // Try to get registerd music by Hashed OCR Data
                logger.Info("Try to get music by Hashed OCR Data.");
                Music registeredMusic = musicDao.selectByHashedOcrData(analyzedMusic.hashedOcrData);
                if (registeredMusic == null)
                {
                    logger.Info("Try to get OCR readed music by title & level & difficult");
                    registeredMusic = musicDao.selectByTitleDifficultLevel(analyzedMusic.title, analyzedMusic.level, analyzedMusic.difficult);
                }

                if (registeredMusic == null)
                {
                    logger.Info("This is new regist music.");
                }
                else
                {
                    logger.Info("This is registered music.");
                    // Load title from DB
                    analyzedMusic.id                = registeredMusic.id;
                    analyzedMusic.title             = registeredMusic.title;
                    analyzedMusic.difficult         = registeredMusic.difficult;
                    analyzedMusic.level             = registeredMusic.level;
                    analyzedMusic.hashedOcrDataList = registeredMusic.hashedOcrDataList;
                }

                // Confirm data
                using (RegistScoreConfirmForm confirmForm = new RegistScoreConfirmForm(ref analyzedMusic, ref registeredMusic))
                {
                    if (DialogResult.OK == confirmForm.ShowDialog())
                    {
                        logger.Info("DialogResult is ok.");

                        if (registeredMusic == null)
                        {
                            logger.Info("Registered music is null. final check user inputed date (update or insert).");
                            // Check db master from title, difficult, level - if matched, update data.
                            registeredMusic = musicDao.selectByTitleDifficultLevel(analyzedMusic.title, analyzedMusic.level, analyzedMusic.difficult);
                            if (registeredMusic == null)
                            {
                                // Insert
                                logger.Info("User inputed date is not matched to database. Execute insert.");
                            }
                            else
                            {
                                // Update
                                logger.Info("User inputed date is matched to database. Execute update.");
                                // Attach data value
                                analyzedMusic.id = registeredMusic.id;
                                analyzedMusic.hashedOcrDataList = registeredMusic.hashedOcrDataList;
                            }
                        }
                        else
                        {
                            logger.Info("Registered music is not null, update execute.");
                        }

                        musicDao.InsertOrReplace(analyzedMusic);
                    }
                    else
                    {
                        // If canceled, delete work file
                        string workfileOutputPath = dataFolderPath
                                                    + Path.DirectorySeparatorChar
                                                    + Path.GetFileNameWithoutExtension(filePath);
                        logger.Info("DialogResult is cancel, cleanup score data. Directory path = " + workfileOutputPath);
                        if (Directory.Exists(workfileOutputPath) == true)
                        {
                            Directory.Delete(workfileOutputPath, true);
                        }
                    }
                }
            }
            logger.Info("Analyze end.");
            logger.Info("Analyze score end.");
        }