Advertisement
Guest User

Untitled

a guest
Jan 7th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Runtime.Serialization;
  11. using System.Runtime.Serialization.Formatters.Binary;
  12.  
  13. using Pathfinder;
  14.  
  15. namespace Thaumcraft_Pathfinder
  16. {
  17.   public partial class frmMain : Form
  18.   {
  19.     private string       ScriptsDir = Application.StartupPath + "\\Scripts\\";
  20.     private string       AppData    = Application.StartupPath + "\\Pathfinder.dat";
  21.     private List<string> Versions   = new List<string>();
  22.     private AppStateData AppState   = new AppStateData();
  23.  
  24.     private Dictionary<string, List<Aspect>> Aspects = new Dictionary<string, List<Aspect>>();
  25.  
  26.     public frmMain()
  27.     {
  28.       InitializeComponent();
  29.  
  30.       numMaxLen.MouseWheel += new MouseEventHandler( this.MouseWheelScrollHandler );
  31.       numMinLen.MouseWheel += new MouseEventHandler( this.MouseWheelScrollHandler );
  32.     }
  33.  
  34.     private void FindScripts()
  35.     {
  36.       if ( Directory.Exists( ScriptsDir ) == false )
  37.       {
  38.         MessageBox.Show( "No scripts detected!  The program can't function without them!  Please, ensure that the Scripts folder is inside the main program folder, and contains *.pfa files in its subdirectories." );
  39.         throw new DirectoryNotFoundException( ScriptsDir );
  40.       }
  41.       else
  42.       {
  43.         DirectoryInfo ScrDirInfo = new DirectoryInfo( ScriptsDir );
  44.  
  45.         foreach ( DirectoryInfo SubDir in ScrDirInfo.GetDirectories() )
  46.         {
  47.           if ( SubDir.Name[SubDir.Name.Length - 1] == '\\' )
  48.           {
  49.             Versions.Add( Path.GetFileName( SubDir.Name.Remove( SubDir.Name.Length - 1 ) ) );
  50.           }
  51.           else
  52.           {
  53.             Versions.Add( Path.GetFileName( SubDir.Name ) );
  54.           }
  55.         }
  56.       }
  57.  
  58.       foreach ( string Ver in Versions )
  59.       {
  60.         cboVersion.Items.Add( Ver );
  61.       }
  62.  
  63.       cboVersion.SelectedIndex = 0;
  64.  
  65.       LoadScripts();
  66.     }
  67.  
  68.     private void LoadScripts()
  69.     {
  70.       foreach ( string Version in Versions )
  71.       {
  72.         List<Aspect> AspectList = new List<Aspect>();
  73.  
  74.         foreach ( string Script in Directory.GetFiles( ScriptsDir + Version + "\\" ) )
  75.         {
  76.           FileStream      stream    = File.Open( Script, FileMode.Open );
  77.           BinaryFormatter formatter = new BinaryFormatter();
  78.           Aspect          aspect    = ( Aspect ) formatter.Deserialize( stream );
  79.  
  80.           AspectList.Add( aspect );
  81.         }
  82.  
  83.         Aspects.Add( Version, AspectList );
  84.       }
  85.     }
  86.  
  87.     private void LoadStateData()
  88.     {
  89.       if ( File.Exists( AppData ) == true )
  90.       {
  91.         FileStream      stream    = File.Open( AppData, FileMode.Open );
  92.         BinaryFormatter formatter = new BinaryFormatter();
  93.  
  94.         this.AppState = ( AppStateData ) formatter.Deserialize( stream );
  95.         stream.Close();
  96.       }
  97.       else
  98.       {
  99.         SaveStateData();
  100.       }
  101.     }
  102.  
  103.     private void SaveStateData()
  104.     {
  105.       FileStream      stream    = File.Open( AppData, FileMode.OpenOrCreate );
  106.       BinaryFormatter formatter = new BinaryFormatter();
  107.  
  108.       formatter.Serialize( stream, this.AppState );
  109.       stream.Close();
  110.     }
  111.  
  112.     private void frmMain_Load( object sender, EventArgs e )
  113.     {
  114.       FindScripts();
  115.       LoadStateData();
  116.     }
  117.  
  118.     private void aboutToolStripMenuItem_Click( object sender, EventArgs e )
  119.     {
  120.       new frmAbout().Show();
  121.     }
  122.  
  123.     private void MouseWheelScrollHandler( object sender, MouseEventArgs e )
  124.     {
  125.       NumericUpDown         Ctrl        = ( NumericUpDown ) sender;
  126.       HandledMouseEventArgs HandledArgs = e as HandledMouseEventArgs;
  127.       HandledArgs.Handled               = true;
  128.  
  129.       decimal Value = Ctrl.Value + ( ( e.Delta > 0 ) ? Ctrl.Increment : -Ctrl.Increment );
  130.       Ctrl.Value = Math.Max( Ctrl.Minimum, Math.Min( Value, Ctrl.Maximum ) );
  131.     }
  132.  
  133.     private void cboVersion_SelectedIndexChanged( object sender, EventArgs e )
  134.     {
  135.  
  136.     }
  137.   }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement