public override void getFilesInDirectory( )//string directory ) { base.getFilesInDirectory( ); selected = null; FileHeader[] fileBuffer = files; files = new FileHeader[ files.Length + 1 ]; fileBuffer.CopyTo( files, 1 ); files[ 0 ] = new NewFileHeader(); /* for ( int i = 1; i < files.Length; i++ ) if ( files[ i ].path == lastPath ) { selected = files[ i ]; if ( i > maxOnScreen ) posAtTop = i - maxOnScreen; break; } if ( selected == null )*/ selected = files[ 0 ]; }
public override void getFilesInDirectory() // string directory ) { string atoDir = directory + @"auto\"; if ( !System.IO.Directory.Exists( directory ) ) System.IO.Directory.CreateDirectory( directory ); if ( !System.IO.Directory.Exists( atoDir ) ) System.IO.Directory.CreateDirectory( atoDir ); string[] normalPaths = System.IO.Directory.GetFiles( directory ), autoPaths = System.IO.Directory.GetFiles( atoDir ); string[] paths = new string[ normalPaths.Length + autoPaths.Length ]; normalPaths.CopyTo( paths, 0 ); autoPaths.CopyTo( paths, normalPaths.Length ); int pos = 0; for ( int i = 0; i < paths.Length; i ++ ) if ( System.IO.Path.GetExtension( paths[ i ] ) == ( scenario? ".phm" : ".phs") ) pos ++; else paths[ i ] = null; FileHeader[] tempFiles = new FileHeader[ pos ]; pos = 0; for ( int i = 0; i < paths.Length; i ++ ) if ( paths[ i ] != null ) { tempFiles[ pos ] = FileHeader.getFromPath( paths[ i ] ); if ( tempFiles[ pos ] != null ) pos ++; } files = new FileHeader[ pos ]; pos = 0; for ( int i = 0; i < tempFiles.Length; i ++ ) if ( tempFiles[ i ] != null ) { files[ pos ] = tempFiles[ i ]; // FileHeader.getFrom( paths[ i ] ); pos ++; } foreach ( FileHeader file in files ) { string dir = System.IO.Path.GetFileName( System.IO.Path.GetDirectoryName( file.path ) ); if ( dir != "saves" ) file.name = dir + @" \ "+ file.name; } posAtTop = 0; if ( files.Length > 0 ) selected = files[ 0 ]; }
public static FileHeader getFromStream( FileHeader intro, string path, int version, BinaryReader reader ) { intro.path = path; intro.modified = System.IO.File.GetLastWriteTime( path ); if ( version == 887 ) { intro.type = (Type)reader.ReadByte(); if ( intro.type == Type.playedGame ) // normal { intro.name = System.IO.Path.GetFileNameWithoutExtension( path ); intro.playerName = reader.ReadString(); intro.civName = reader.ReadString(); intro.turn = reader.ReadInt32(); loadMap( intro, reader ); } else if ( intro.type == Type.playedScenario ) // played scenario { intro.playerName = reader.ReadString(); intro.civName = reader.ReadString(); intro.name = System.IO.Path.GetFileNameWithoutExtension( path ); intro.scenarioName = reader.ReadString(); intro.turn = reader.ReadInt32(); loadMap( intro, reader ); intro.goalType = (Scenario.GoalType)reader.ReadByte(); intro.goalInd = reader.ReadInt32(); } else if ( intro.type == Type.scenario ) // scenario { intro.name = reader.ReadString(); intro.description = reader.ReadString(); intro.turn = reader.ReadInt32(); loadMap( intro, reader ); intro.goalType = (Scenario.GoalType)reader.ReadByte(); intro.goalInd = reader.ReadInt32(); } } else { intro.playerName = "-"; intro.civName = "-"; intro.turn = 0; intro.name = System.IO.Path.GetFileNameWithoutExtension( path ); } return intro; }
public static FileHeader getFromPath( string path ) { FileHeader intro = new FileHeader(); FileStream file = null; BinaryReader reader = null; bool success; // intro.path = path; try { file = new FileStream( path, FileMode.Open, FileAccess.Read ); reader = new BinaryReader( file ); int version = reader.ReadInt32(); intro = getFromStream( intro, path, version, reader ); success = true; } catch ( Exception /*e*/ ) { success = false; } finally { if ( file != null ) file.Close(); if ( reader != null ) reader.Close(); } if ( success ) return intro; else return null; }
/* public static void loadMap( int width, int height, BinaryReader reader ) { FileHeader intro = new FileHeader(); // intro. loadMap } */ public static void loadMap( FileHeader intro, BinaryReader reader ) { if ( intro == null ) intro = new FileHeader(); intro.bmp = new Bitmap( reader.ReadInt32(), reader.ReadInt32() ); Color[] colors = new Color[ reader.ReadInt32() ]; for ( int c = 0; c < colors.Length; c ++ ) colors[ c ] = Color.FromArgb( reader.ReadInt32() ); for ( int x = 0; x < intro.bmp.Width; x ++ ) for ( int y = 0; y < intro.bmp.Height; y ++ ) intro.bmp.SetPixel( x, y, colors[ reader.ReadByte() ] ); // Color.FromArgb( reader.ReadInt32() ) ); }
protected override void OnMouseUp(MouseEventArgs e) { if ( e.Y < topBorder ) goUp(); else if ( e.Y > topBorder + maxOnScreen * (itemHeight + borders) ) { // int bob = topBorder + maxOnScreen * (itemHeight + borders); goDown(); } else for ( int i = posAtTop, pos = 0; i < files.Length && pos < maxOnScreen; i ++, pos ++ ) if ( getRectAtPos( pos ).Contains( e.X, e.Y ) ) { if ( selected != files[ i ] ) { selected = files[ i ]; indSelected = i; drawFrames(); } break; } }
public virtual void getFilesInDirectory()// string directory ) { if ( !System.IO.Directory.Exists( directory ) ) System.IO.Directory.CreateDirectory( directory ); string[] paths = System.IO.Directory.GetFiles( directory )/*, dirs = System.IO.Directory.GetDirectories( directory )*/; int pos = 0; for ( int i = 0; i < paths.Length; i ++ ) if ( System.IO.Path.GetExtension( paths[ i ] ) == ( scenario? ".phm" : ".phs") ) pos ++; else paths[ i ] = null; FileHeader[] tempFiles = new FileHeader[ pos ]; pos = 0; for ( int i = 0; i < paths.Length; i ++ ) if ( paths[ i ] != null ) { tempFiles[ pos ] = FileHeader.getFromPath( paths[ i ] ); if ( tempFiles[ pos ] != null ) pos ++; } files = new FileHeader[ pos ]; pos = 0; for ( int i = 0; i < tempFiles.Length; i ++ ) if ( tempFiles[ i ] != null ) { files[ pos ] = tempFiles[ i ]; // FileHeader.getFrom( paths[ i ] ); pos ++; } posAtTop = 0; if ( files.Length > 0 ) selected = files[ 0 ]; }