2011-02-11 02:30:45 +00:00
using System ;
2014-05-15 23:12:48 +00:00
using System.Threading.Tasks ;
2011-02-11 02:30:45 +00:00
using System.Collections.Generic ;
using System.Drawing ;
2014-04-13 22:43:30 +00:00
using System.IO ;
2013-10-28 00:21:00 +00:00
using System.Linq ;
2011-02-11 02:30:45 +00:00
using System.Text ;
using System.Windows.Forms ;
2013-10-25 00:57:23 +00:00
using BizHawk.Client.Common ;
2014-04-13 22:43:30 +00:00
using BizHawk.Common ;
2013-10-25 00:57:23 +00:00
2013-11-03 03:54:37 +00:00
namespace BizHawk.Client.EmuHawk
2011-02-11 02:30:45 +00:00
{
2014-04-13 22:16:47 +00:00
public partial class PlayMovie : Form
{
2014-06-08 19:36:33 +00:00
// Movies 2.0 TODO: this is hopelessly Movie.cs specific, to make it generic, make a MovieLoader class that receives a path and returns an IMovie, that does the logic of determining bkm, bk2, or tasproj
2014-04-13 22:16:47 +00:00
private List < IMovie > _movieList = new List < IMovie > ( ) ;
private bool _sortReverse ;
private string _sortedCol ;
private bool _sortDetailsReverse ;
private string _sortedDetailsCol ;
public PlayMovie ( )
{
InitializeComponent ( ) ;
MovieView . QueryItemText + = MovieView_QueryItemText ;
MovieView . VirtualMode = true ;
_sortReverse = false ;
2014-04-13 22:43:30 +00:00
_sortedCol = string . Empty ;
2014-04-13 22:16:47 +00:00
_sortDetailsReverse = false ;
2014-04-13 22:43:30 +00:00
_sortedDetailsCol = string . Empty ;
}
private void PlayMovie_Load ( object sender , EventArgs e )
{
IncludeSubDirectories . Checked = Global . Config . PlayMovie_IncludeSubdir ;
ShowStateFiles . Checked = Global . Config . PlayMovie_ShowStateFiles ;
2014-04-26 17:54:56 +00:00
MatchHashCheckBox . Checked = Global . Config . PlayMovie_MatchHash ;
2014-04-13 22:43:30 +00:00
ScanFiles ( ) ;
PreHighlightMovie ( ) ;
2014-04-13 22:16:47 +00:00
}
2014-04-13 22:43:30 +00:00
private void MovieView_QueryItemText ( int index , int column , out string text )
2014-04-13 22:16:47 +00:00
{
2014-04-13 22:43:30 +00:00
text = string . Empty ;
if ( column = = 0 ) // File
2014-04-13 22:16:47 +00:00
{
text = Path . GetFileName ( _movieList [ index ] . Filename ) ;
}
2014-04-13 22:43:30 +00:00
if ( column = = 1 ) // System
2014-04-13 22:16:47 +00:00
{
text = _movieList [ index ] . Header . SystemID ;
}
2014-04-13 22:43:30 +00:00
if ( column = = 2 ) // Game
2014-04-13 22:16:47 +00:00
{
text = _movieList [ index ] . Header . GameName ;
}
2014-04-13 22:43:30 +00:00
if ( column = = 3 ) // Time
2014-04-13 22:16:47 +00:00
{
text = _movieList [ index ] . Time . ToString ( @"hh\:mm\:ss\.fff" ) ;
}
}
private void Run ( )
{
var indices = MovieView . SelectedIndices ;
2014-04-13 22:43:30 +00:00
if ( indices . Count > 0 ) // Import file if necessary
2014-04-13 22:16:47 +00:00
{
GlobalWin . MainForm . StartNewMovie ( _movieList [ MovieView . SelectedIndices [ 0 ] ] , false ) ;
}
}
private void AddStateToList ( string filename )
{
using ( var file = new HawkFile ( filename ) )
{
if ( file . Exists )
{
if ( ! IsDuplicateOf ( filename ) . HasValue )
{
var movie = new Movie ( file . CanonicalFullPath ) ;
2014-04-13 22:43:30 +00:00
movie . Load ( ) ; // State files will have to load everything unfortunately
2014-04-13 22:16:47 +00:00
if ( movie . FrameCount > 0 )
{
_movieList . Add ( movie ) ;
_sortReverse = false ;
2014-04-13 22:43:30 +00:00
_sortedCol = string . Empty ;
2014-04-13 22:16:47 +00:00
}
}
}
}
}
private int? AddMovieToList ( string filename , bool force )
{
using ( var file = new HawkFile ( filename ) )
{
if ( ! file . Exists )
{
return null ;
}
2014-04-13 22:43:30 +00:00
var index = IsDuplicateOf ( filename ) ;
if ( ! index . HasValue )
2014-04-13 22:16:47 +00:00
{
2014-05-16 00:12:08 +00:00
//System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start();
2014-05-15 23:12:48 +00:00
var movie = PreLoadMovieFile ( file , force ) ;
2014-06-10 01:10:54 +00:00
if ( movie = = null )
{
return null ;
}
2014-05-16 00:12:08 +00:00
//watch.Stop(); Console.WriteLine("[{0}] {1}",watch.ElapsedMilliseconds,Path.GetFileName(filename));
2014-06-10 01:10:54 +00:00
2014-05-15 23:12:48 +00:00
lock ( _movieList )
{
_movieList . Add ( movie ) ;
index = _movieList . Count - 1 ;
}
2014-04-13 22:16:47 +00:00
2014-04-13 22:43:30 +00:00
_sortReverse = false ;
_sortedCol = string . Empty ;
2014-04-13 22:16:47 +00:00
}
2014-04-13 22:43:30 +00:00
return index ;
2014-04-13 22:16:47 +00:00
}
2014-05-15 23:12:48 +00:00
2014-04-13 22:16:47 +00:00
}
private int? IsDuplicateOf ( string filename )
{
2014-04-13 22:43:30 +00:00
for ( var i = 0 ; i < _movieList . Count ; i + + )
2014-04-13 22:16:47 +00:00
{
if ( _movieList [ i ] . Filename = = filename )
{
return i ;
}
}
return null ;
}
2014-05-15 23:12:48 +00:00
private Movie PreLoadMovieFile ( HawkFile hf , bool force )
2014-04-13 22:16:47 +00:00
{
var movie = new Movie ( hf . CanonicalFullPath ) ;
2014-04-13 23:18:45 +00:00
2014-04-13 22:16:47 +00:00
try
{
2014-04-13 23:18:45 +00:00
movie . PreLoadText ( hf ) ;
2014-04-13 22:43:30 +00:00
// Don't do this from browse
2014-04-26 17:54:56 +00:00
if ( movie . Header [ HeaderKeys . SHA1 ] = = Global . Game . Hash | |
Global . Config . PlayMovie_MatchHash = = false | | force )
2014-04-13 22:16:47 +00:00
{
2014-05-15 23:12:48 +00:00
return movie ;
2014-04-13 22:16:47 +00:00
}
}
catch ( Exception ex )
{
2014-04-13 23:18:45 +00:00
// TODO: inform the user that a movie failed to parse in some way
2014-04-13 22:16:47 +00:00
Console . WriteLine ( ex . Message ) ;
}
2014-05-15 23:12:48 +00:00
return null ;
2014-04-13 22:16:47 +00:00
}
private void UpdateList ( )
{
MovieView . Refresh ( ) ;
MovieCount . Text = _movieList . Count + " movie"
2014-04-13 22:43:30 +00:00
+ ( _movieList . Count ! = 1 ? "s" : string . Empty ) ;
2014-04-13 22:16:47 +00:00
}
private void PreHighlightMovie ( )
{
2014-04-13 22:43:30 +00:00
if ( Global . Game = = null )
{
return ;
}
var indices = new List < int > ( ) ;
2014-04-13 22:16:47 +00:00
2014-04-13 22:43:30 +00:00
// Pull out matching names
for ( var i = 0 ; i < _movieList . Count ; i + + )
2014-04-13 22:16:47 +00:00
{
if ( PathManager . FilesystemSafeName ( Global . Game ) = = _movieList [ i ] . Header . GameName )
{
2014-04-13 22:43:30 +00:00
indices . Add ( i ) ;
2014-04-13 22:16:47 +00:00
}
}
2014-04-13 22:43:30 +00:00
if ( indices . Count = = 0 )
{
return ;
}
if ( indices . Count = = 1 )
2014-04-13 22:16:47 +00:00
{
2014-04-13 22:43:30 +00:00
HighlightMovie ( indices [ 0 ] ) ;
2014-04-13 22:16:47 +00:00
return ;
}
2014-04-13 22:43:30 +00:00
// Prefer tas files
var tas = new List < int > ( ) ;
for ( var i = 0 ; i < indices . Count ; i + + )
2014-04-13 22:16:47 +00:00
{
2014-06-08 19:36:33 +00:00
if ( Path . GetExtension ( _movieList [ indices [ i ] ] . Filename ) . ToUpper ( ) = = "." + Movie . Extension )
2014-04-13 22:16:47 +00:00
{
2014-04-13 22:43:30 +00:00
tas . Add ( i ) ;
2014-04-13 22:16:47 +00:00
}
}
2014-04-13 22:43:30 +00:00
if ( tas . Count = = 1 )
2014-04-13 22:16:47 +00:00
{
2014-04-13 22:43:30 +00:00
HighlightMovie ( tas [ 0 ] ) ;
2014-04-13 22:16:47 +00:00
return ;
}
2014-04-13 22:43:30 +00:00
if ( tas . Count > 1 )
2014-04-13 22:16:47 +00:00
{
2014-04-13 22:43:30 +00:00
indices = new List < int > ( tas ) ;
2014-04-13 22:16:47 +00:00
}
2014-04-13 22:43:30 +00:00
// Final tie breaker - Last used file
var file = new FileInfo ( _movieList [ indices [ 0 ] ] . Filename ) ;
2014-04-13 22:16:47 +00:00
var time = file . LastAccessTime ;
2014-04-13 22:43:30 +00:00
var mostRecent = indices . First ( ) ;
for ( var i = 1 ; i < indices . Count ; i + + )
2014-04-13 22:16:47 +00:00
{
2014-04-13 22:43:30 +00:00
file = new FileInfo ( _movieList [ indices [ 0 ] ] . Filename ) ;
2014-04-13 22:16:47 +00:00
if ( file . LastAccessTime > time )
{
time = file . LastAccessTime ;
2014-04-13 22:43:30 +00:00
mostRecent = indices [ i ] ;
2014-04-13 22:16:47 +00:00
}
}
HighlightMovie ( mostRecent ) ;
return ;
}
private void HighlightMovie ( int index )
{
MovieView . SelectedIndices . Clear ( ) ;
MovieView . setSelection ( index ) ;
MovieView . SelectItem ( index , true ) ;
}
2014-04-13 22:43:30 +00:00
private void ScanFiles ( )
2014-04-13 22:16:47 +00:00
{
_movieList . Clear ( ) ;
MovieView . ItemCount = 0 ;
MovieView . Update ( ) ;
var directory = PathManager . MakeAbsolutePath ( Global . Config . PathEntries . MoviesPathFragment , null ) ;
if ( ! Directory . Exists ( directory ) )
{
Directory . CreateDirectory ( directory ) ;
}
2014-05-15 23:12:48 +00:00
var dpTodo = new Queue < string > ( ) ;
var fpTodo = new List < string > ( ) ;
dpTodo . Enqueue ( directory ) ;
Dictionary < string , int > ordinals = new Dictionary < string , int > ( ) ;
2014-04-13 22:16:47 +00:00
2014-05-15 23:12:48 +00:00
while ( dpTodo . Count > 0 )
2014-04-13 22:16:47 +00:00
{
2014-05-15 23:12:48 +00:00
string dp = dpTodo . Dequeue ( ) ;
//enqueue subdirectories if appropriate
if ( Global . Config . PlayMovie_IncludeSubdir )
foreach ( var subdir in Directory . GetDirectories ( dp ) )
dpTodo . Enqueue ( subdir ) ;
//add movies
2014-06-08 19:36:33 +00:00
fpTodo . AddRange ( Directory . GetFiles ( dp , "*." + Movie . Extension ) ) ;
2014-05-15 23:12:48 +00:00
//add states if requested
if ( Global . Config . PlayMovie_ShowStateFiles )
fpTodo . AddRange ( Directory . GetFiles ( dp , "*.state" ) ) ;
2014-04-13 22:16:47 +00:00
}
2014-05-15 23:12:48 +00:00
//in parallel, scan each movie
Parallel . For ( 0 , fpTodo . Count , ( i ) = >
2014-05-16 00:12:08 +00:00
//for(int i=0;i<fpTodo.Count;i++)
2014-04-13 22:16:47 +00:00
{
2014-05-15 23:12:48 +00:00
var file = fpTodo [ i ] ;
lock ( ordinals ) ordinals [ file ] = i ;
AddMovieToList ( file , force : false ) ;
2014-05-16 00:12:08 +00:00
}
) ;
2014-04-13 22:16:47 +00:00
2014-05-15 23:12:48 +00:00
//sort by the ordinal key to maintain relatively stable results when rescanning
_movieList . Sort ( ( a , b ) = > ordinals [ a . Filename ] . CompareTo ( ordinals [ b . Filename ] ) ) ;
RefreshMovieList ( ) ;
2014-04-13 22:16:47 +00:00
}
2014-04-13 22:43:30 +00:00
#region Events
2014-04-13 22:16:47 +00:00
2014-04-13 22:43:30 +00:00
#region Movie List
2014-04-13 22:16:47 +00:00
2014-05-15 23:12:48 +00:00
void RefreshMovieList ( )
{
MovieView . ItemCount = _movieList . Count ;
UpdateList ( ) ;
}
2014-04-13 22:16:47 +00:00
private void MovieView_DragEnter ( object sender , DragEventArgs e )
{
e . Effect = e . Data . GetDataPresent ( DataFormats . FileDrop ) ? DragDropEffects . Copy : DragDropEffects . None ;
}
private void MovieView_DragDrop ( object sender , DragEventArgs e )
{
var filePaths = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
filePaths
2014-06-08 19:36:33 +00:00
. Where ( path = > Path . GetExtension ( path ) = = "." + Movie . Extension )
2014-04-13 22:16:47 +00:00
. ToList ( )
. ForEach ( path = > AddMovieToList ( path , force : true ) ) ;
2014-05-15 23:12:48 +00:00
RefreshMovieList ( ) ;
2014-04-13 22:16:47 +00:00
}
2014-04-13 22:43:30 +00:00
private void MovieView_KeyDown ( object sender , KeyEventArgs e )
{
if ( e . Control & & e . KeyCode = = Keys . C )
{
var indexes = MovieView . SelectedIndices ;
if ( indexes . Count > 0 )
{
var copyStr = new StringBuilder ( ) ;
foreach ( int index in indexes )
{
copyStr
. Append ( _movieList [ index ] . Filename ) . Append ( '\t' )
. Append ( _movieList [ index ] . Header . SystemID ) . Append ( '\t' )
. Append ( _movieList [ index ] . Header . GameName ) . Append ( '\t' )
. Append ( _movieList [ index ] . Time . ToString ( @"hh\:mm\:ss\.fff" ) )
. AppendLine ( ) ;
Clipboard . SetDataObject ( copyStr . ToString ( ) ) ;
}
}
}
}
private void MovieView_DoubleClick ( object sender , EventArgs e )
2014-04-13 22:16:47 +00:00
{
2014-04-13 22:43:30 +00:00
Run ( ) ;
Close ( ) ;
2014-04-13 22:16:47 +00:00
}
2014-04-13 22:43:30 +00:00
private void MovieView_ColumnClick ( object sender , ColumnClickEventArgs e )
2014-04-13 22:16:47 +00:00
{
2014-04-13 22:43:30 +00:00
var columnName = MovieView . Columns [ e . Column ] . Text ;
2014-04-13 22:16:47 +00:00
if ( _sortedCol ! = columnName )
{
_sortReverse = false ;
}
switch ( columnName )
{
case "File" :
if ( _sortReverse )
{
_movieList = _movieList
. OrderByDescending ( x = > Path . GetFileName ( x . Filename ) )
. ThenBy ( x = > x . Header . SystemID )
. ThenBy ( x = > x . Header . GameName )
. ThenBy ( x = > x . FrameCount )
. ToList ( ) ;
}
else
{
_movieList = _movieList
. OrderBy ( x = > Path . GetFileName ( x . Filename ) )
. ThenBy ( x = > x . Header . SystemID )
. ThenBy ( x = > x . Header . GameName )
. ThenBy ( x = > x . FrameCount )
. ToList ( ) ;
}
break ;
case "SysID" :
if ( _sortReverse )
{
_movieList = _movieList
. OrderByDescending ( x = > x . Header . SystemID )
. ThenBy ( x = > Path . GetFileName ( x . Filename ) )
. ThenBy ( x = > x . Header . GameName )
. ThenBy ( x = > x . FrameCount )
. ToList ( ) ;
}
else
{
_movieList = _movieList
. OrderBy ( x = > x . Header . SystemID )
. ThenBy ( x = > Path . GetFileName ( x . Filename ) )
. ThenBy ( x = > x . Header . GameName )
. ThenBy ( x = > x . FrameCount )
. ToList ( ) ;
}
break ;
case "Game" :
if ( _sortReverse )
{
_movieList = _movieList
. OrderByDescending ( x = > x . Header . GameName )
. ThenBy ( x = > Path . GetFileName ( x . Filename ) )
. ThenBy ( x = > x . Header . SystemID )
. ThenBy ( x = > x . FrameCount )
. ToList ( ) ;
}
else
{
_movieList = _movieList
. OrderBy ( x = > x . Header . GameName )
. ThenBy ( x = > Path . GetFileName ( x . Filename ) )
. ThenBy ( x = > x . Header . SystemID )
. ThenBy ( x = > x . FrameCount )
. ToList ( ) ;
}
break ;
case "Length (est.)" :
if ( _sortReverse )
{
_movieList = _movieList
. OrderByDescending ( x = > x . FrameCount )
. ThenBy ( x = > Path . GetFileName ( x . Filename ) )
. ThenBy ( x = > x . Header . SystemID )
. ThenBy ( x = > x . FrameCount )
. ToList ( ) ;
}
else
{
_movieList = _movieList
. OrderBy ( x = > x . FrameCount )
. ThenBy ( x = > Path . GetFileName ( x . Filename ) )
. ThenBy ( x = > x . Header . SystemID )
. ThenBy ( x = > x . Header . GameName )
. ToList ( ) ;
}
break ;
}
_sortedCol = columnName ;
_sortReverse = ! _sortReverse ;
MovieView . Refresh ( ) ;
}
2014-04-13 22:43:30 +00:00
private void MovieView_SelectedIndexChanged ( object sender , EventArgs e )
2014-04-13 22:16:47 +00:00
{
2014-04-13 22:43:30 +00:00
toolTip1 . SetToolTip ( DetailsView , string . Empty ) ;
DetailsView . Items . Clear ( ) ;
if ( MovieView . SelectedIndices . Count < 1 )
{
OK . Enabled = false ;
return ;
}
2014-04-13 22:16:47 +00:00
2014-04-13 22:43:30 +00:00
OK . Enabled = true ;
2014-04-13 22:16:47 +00:00
2014-04-13 22:43:30 +00:00
var firstIndex = MovieView . SelectedIndices [ 0 ] ;
MovieView . ensureVisible ( firstIndex ) ;
2014-04-13 22:16:47 +00:00
2014-04-13 22:43:30 +00:00
foreach ( var kvp in _movieList [ firstIndex ] . Header )
2014-04-13 22:16:47 +00:00
{
2014-04-13 22:43:30 +00:00
var item = new ListViewItem ( kvp . Key ) ;
item . SubItems . Add ( kvp . Value ) ;
2014-04-13 22:16:47 +00:00
2014-05-15 23:12:48 +00:00
bool add = true ;
2014-04-13 22:43:30 +00:00
switch ( kvp . Key )
{
case HeaderKeys . SHA1 :
if ( kvp . Value ! = Global . Game . Hash )
{
item . BackColor = Color . Pink ;
toolTip1 . SetToolTip ( DetailsView , "Current SHA1: " + Global . Game . Hash ) ;
}
break ;
case HeaderKeys . MOVIEVERSION :
if ( kvp . Value ! = HeaderKeys . MovieVersion1 )
{
item . BackColor = Color . Yellow ;
}
break ;
case HeaderKeys . EMULATIONVERSION :
if ( kvp . Value ! = VersionInfo . GetEmuVersion ( ) )
{
item . BackColor = Color . Yellow ;
}
break ;
case HeaderKeys . PLATFORM :
if ( kvp . Value ! = Global . Game . System )
{
item . BackColor = Color . Pink ;
}
break ;
2014-04-13 22:16:47 +00:00
}
2014-04-13 22:43:30 +00:00
2014-05-15 23:12:48 +00:00
if ( add )
DetailsView . Items . Add ( item ) ;
2014-04-13 22:16:47 +00:00
}
2014-04-13 22:43:30 +00:00
var FpsItem = new ListViewItem ( "Fps" ) ;
FpsItem . SubItems . Add ( string . Format ( "{0:0.#######}" , _movieList [ firstIndex ] . Fps ) ) ;
DetailsView . Items . Add ( FpsItem ) ;
var FramesItem = new ListViewItem ( "Frames" ) ;
FramesItem . SubItems . Add ( _movieList [ firstIndex ] . FrameCount . ToString ( ) ) ;
DetailsView . Items . Add ( FramesItem ) ;
2014-06-08 22:12:15 +00:00
CommentsBtn . Enabled = _movieList [ firstIndex ] . Comments . Any ( ) ;
SubtitlesBtn . Enabled = _movieList [ firstIndex ] . Subtitles . Any ( ) ;
2014-04-13 22:16:47 +00:00
}
2014-04-22 00:59:21 +00:00
private void EditMenuItem_Click ( object sender , EventArgs e )
{
MovieView . SelectedIndices
. Cast < int > ( )
. Select ( index = > _movieList [ index ] )
. ToList ( )
. ForEach ( movie = > System . Diagnostics . Process . Start ( movie . Filename ) ) ;
}
2014-04-13 22:43:30 +00:00
#endregion
#region Details
private void DetailsView_ColumnClick ( object sender , ColumnClickEventArgs e )
2014-04-13 22:16:47 +00:00
{
2014-04-13 22:43:30 +00:00
var detailsList = new List < MovieDetails > ( ) ;
for ( var i = 0 ; i < DetailsView . Items . Count ; i + + )
2014-04-13 22:16:47 +00:00
{
2014-04-13 22:43:30 +00:00
detailsList . Add ( new MovieDetails
{
Keys = DetailsView . Items [ i ] . Text ,
Values = DetailsView . Items [ i ] . SubItems [ 1 ] . Text ,
BackgroundColor = DetailsView . Items [ i ] . BackColor
} ) ;
2014-04-13 22:16:47 +00:00
}
2014-04-13 22:43:30 +00:00
var columnName = DetailsView . Columns [ e . Column ] . Text ;
2014-04-13 22:16:47 +00:00
if ( _sortedDetailsCol ! = columnName )
{
_sortDetailsReverse = false ;
}
2014-04-13 22:43:30 +00:00
2014-04-13 22:16:47 +00:00
switch ( columnName )
{
2014-04-13 22:43:30 +00:00
// Header, Value
2014-04-13 22:16:47 +00:00
case "Header" :
if ( _sortDetailsReverse )
{
detailsList = detailsList
2014-04-13 22:43:30 +00:00
. OrderByDescending ( x = > x . Keys )
. ThenBy ( x = > x . Values ) . ToList ( ) ;
2014-04-13 22:16:47 +00:00
}
else
{
detailsList = detailsList
2014-04-13 22:43:30 +00:00
. OrderBy ( x = > x . Keys )
. ThenBy ( x = > x . Values ) . ToList ( ) ;
2014-04-13 22:16:47 +00:00
}
2014-04-13 22:43:30 +00:00
2014-04-13 22:16:47 +00:00
break ;
case "Value" :
if ( _sortDetailsReverse )
{
detailsList = detailsList
2014-04-13 22:43:30 +00:00
. OrderByDescending ( x = > x . Values )
. ThenBy ( x = > x . Keys ) . ToList ( ) ;
2014-04-13 22:16:47 +00:00
}
else
{
detailsList = detailsList
2014-04-13 22:43:30 +00:00
. OrderBy ( x = > x . Values )
. ThenBy ( x = > x . Keys ) . ToList ( ) ;
2014-04-13 22:16:47 +00:00
}
2014-04-13 22:43:30 +00:00
2014-04-13 22:16:47 +00:00
break ;
}
2014-04-13 22:43:30 +00:00
2014-04-13 22:16:47 +00:00
DetailsView . Items . Clear ( ) ;
foreach ( var detail in detailsList )
{
2014-04-13 22:43:30 +00:00
var item = new ListViewItem { Text = detail . Keys , BackColor = detail . BackgroundColor } ;
item . SubItems . Add ( detail . Values ) ;
2014-04-13 22:16:47 +00:00
DetailsView . Items . Add ( item ) ;
}
2014-04-13 22:43:30 +00:00
2014-04-13 22:16:47 +00:00
_sortedDetailsCol = columnName ;
_sortDetailsReverse = ! _sortDetailsReverse ;
}
2014-04-13 22:43:30 +00:00
private void CommentsBtn_Click ( object sender , EventArgs e )
{
var indices = MovieView . SelectedIndices ;
if ( indices . Count > 0 )
{
var form = new EditCommentsForm ( ) ;
form . GetMovie ( _movieList [ MovieView . SelectedIndices [ 0 ] ] ) ;
form . Show ( ) ;
}
}
private void SubtitlesBtn_Click ( object sender , EventArgs e )
{
var indices = MovieView . SelectedIndices ;
if ( indices . Count > 0 )
{
var s = new EditSubtitlesForm { ReadOnly = true } ;
s . GetMovie ( _movieList [ MovieView . SelectedIndices [ 0 ] ] ) ;
s . Show ( ) ;
}
}
#endregion
#region Misc Widgets
private void BrowseMovies_Click ( object sender , EventArgs e )
{
var ofd = new OpenFileDialog
{
2014-06-08 19:36:33 +00:00
Filter = "Movie Files (*." + Movie . Extension + ")|*." + Movie . Extension + "|Savestates|*.state|All Files|*.*" ,
2014-04-13 22:43:30 +00:00
InitialDirectory = PathManager . MakeAbsolutePath ( Global . Config . PathEntries . MoviesPathFragment , null )
} ;
var result = ofd . ShowHawkDialog ( ) ;
if ( result = = DialogResult . OK )
{
var file = new FileInfo ( ofd . FileName ) ;
if ( ! file . Exists )
{
return ;
}
if ( file . Extension . ToUpper ( ) = = "STATE" )
{
var movie = new Movie ( file . FullName ) ;
movie . Load ( ) ; // State files will have to load everything unfortunately
if ( movie . FrameCount = = 0 )
{
MessageBox . Show (
"No input log detected in this savestate, aborting" ,
"Can not load file" ,
MessageBoxButtons . OK ,
MessageBoxIcon . Hand ) ;
return ;
}
}
2014-05-15 23:12:48 +00:00
int? index = AddMovieToList ( ofd . FileName , true ) ;
RefreshMovieList ( ) ;
2014-04-13 22:43:30 +00:00
if ( index . HasValue )
{
MovieView . SelectedIndices . Clear ( ) ;
MovieView . setSelection ( index . Value ) ;
MovieView . SelectItem ( index . Value , true ) ;
}
}
}
private void Scan_Click ( object sender , EventArgs e )
{
ScanFiles ( ) ;
PreHighlightMovie ( ) ;
}
private void IncludeSubDirectories_CheckedChanged ( object sender , EventArgs e )
{
Global . Config . PlayMovie_IncludeSubdir = IncludeSubDirectories . Checked ;
ScanFiles ( ) ;
PreHighlightMovie ( ) ;
}
private void ShowStateFiles_CheckedChanged ( object sender , EventArgs e )
{
Global . Config . PlayMovie_ShowStateFiles = ShowStateFiles . Checked ;
ScanFiles ( ) ;
PreHighlightMovie ( ) ;
}
2014-04-26 17:54:56 +00:00
private void MatchHashCheckBox_CheckedChanged ( object sender , EventArgs e )
2014-04-13 22:43:30 +00:00
{
2014-04-26 17:54:56 +00:00
Global . Config . PlayMovie_MatchHash = MatchHashCheckBox . Checked ;
2014-04-13 22:43:30 +00:00
ScanFiles ( ) ;
PreHighlightMovie ( ) ;
}
private void Ok_Click ( object sender , EventArgs e )
{
Run ( ) ;
Global . MovieSession . ReadOnly = ReadOnlyCheckBox . Checked ;
Close ( ) ;
}
private void Cancel_Click ( object sender , EventArgs e )
{
Close ( ) ;
}
#endregion
#endregion
2014-04-13 22:16:47 +00:00
}
2011-02-11 02:30:45 +00:00
}