録画のtsを視聴する時、当然TVTestで見てるんだが倍速で見ているからか結構な確率でTVTestがフリーズする。
そこまでボロな環境ではないと思うんだけど、3倍速はそこまで無茶なんだろうか。
んでフリーズした時、TVTestを終了させてもう一度tsファイルをダブルクリックで開くんだがもうウインドウ閉じちゃってるんだよね。
フリーズの為だけにウインドウを一つ開き続けるのは嫌だ。なので技術で殴る。最初はTVTestの設定ファイルから最後のファイルを抜き出してそれを開くアプリにしようと思ったけど、ハッシュ値しか記録してないんだよね。
一番最初にtsを開く時にこのソフトにファイルをドラッグ&ドロップする手間が発生してしまうけど最初だけは我慢。関連付け差し替える勇気は無い。
んでフリーズしたらTVTestを強制終了させて、このソフトを実行する。直前にドラッグ&ドロップされたファイルのパスを記録してそれを開く。
つか処理のコードはこんだけだ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
protected override void OnStartup(StartupEventArgs e) { if (e.Args.Length == 0) { //以前のコマンドを再実行する String openFilePath = Setting.value.OpenFilePath; if (openFilePath == null) { MessageBox.Show("任意のファイルを本アプリにドラッグ&ドロップして下さい", "ファイル情報なし", MessageBoxButton.OK, MessageBoxImage.Error); } else { openFile(openFilePath); } } else { //渡されたファイルを開く var val = Setting.value; val.OpenFilePath = e.Args[0]; Setting.value = val; openFile(e.Args[0]); } Environment.Exit(0); } private void openFile(String filePath) { Process p = new Process(); p.StartInfo.UseShellExecute = true; p.StartInfo.WorkingDirectory = Path.GetDirectoryName(filePath); p.StartInfo.FileName = @"""" + filePath + @""""; p.Start(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
class Setting { public static SettingClass value { get { if (_instance == null) { _instance = new Setting(); _instance.init(); } return _instance.setting; } set { if (_instance == null) { _instance = new Setting(); _instance.init(); } _instance.save(value); } } private static Setting _instance = null; private SettingClass setting; private String saveFilePath; private Setting() { } private void init() { if (setting != null) { return; } var myPath = Assembly.GetEntryAssembly().Location; var myDirectory = Path.GetDirectoryName(myPath); var myFilenameWithoutExtension = Path.GetFileNameWithoutExtension(myPath); var settingPath = Path.Combine(myDirectory, myFilenameWithoutExtension + ".xml"); saveFilePath = settingPath; if (!File.Exists(saveFilePath)) { setting = new SettingClass(); return; } XmlSerializer serializer = new XmlSerializer(typeof(SettingClass)); StreamReader sr = new StreamReader(saveFilePath, new UTF8Encoding(false)); setting = (SettingClass)serializer.Deserialize(sr); sr.Close(); } private void save(SettingClass value) { XmlSerializer serializer = new XmlSerializer(typeof(SettingClass)); StreamWriter sw = new StreamWriter(saveFilePath, false, new UTF8Encoding(false)); serializer.Serialize(sw, setting); sw.Close(); } } public class SettingClass { public String OpenFilePath { get; set; } } |
Setting.value.OpenFilePathの値がnullの時で処理分けてるけど、これはnullで適切なんだろうか。どこかで初期化処理を入れて値が無い時はnullを””に変えるべきか。それともIsActiveというフラグを追加してパスの有無を判定する専用のフィールドを持つべきなのか。
俺ならこうするアドバイスをお待ちしております。
後はgithubと連携させて、とりあえずよし。積極的に技術力アッピルしたい。
自分用に作ったせま~~いアプリからせま~~い処理を分離して一般化して公開したい。