Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Runtime.Serialization;
- using System.Runtime.Serialization.Formatters.Binary;
- using Pathfinder;
- namespace Thaumcraft_Pathfinder
- {
- public partial class frmMain : Form
- {
- private string ScriptsDir = Application.StartupPath + "\\Scripts\\";
- private string AppData = Application.StartupPath + "\\Pathfinder.dat";
- private List<string> Versions = new List<string>();
- private AppStateData AppState = new AppStateData();
- private Dictionary<string, List<Aspect>> Aspects = new Dictionary<string, List<Aspect>>();
- public frmMain()
- {
- InitializeComponent();
- numMaxLen.MouseWheel += new MouseEventHandler( this.MouseWheelScrollHandler );
- numMinLen.MouseWheel += new MouseEventHandler( this.MouseWheelScrollHandler );
- }
- private void FindScripts()
- {
- if ( Directory.Exists( ScriptsDir ) == false )
- {
- 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." );
- throw new DirectoryNotFoundException( ScriptsDir );
- }
- else
- {
- DirectoryInfo ScrDirInfo = new DirectoryInfo( ScriptsDir );
- foreach ( DirectoryInfo SubDir in ScrDirInfo.GetDirectories() )
- {
- if ( SubDir.Name[SubDir.Name.Length - 1] == '\\' )
- {
- Versions.Add( Path.GetFileName( SubDir.Name.Remove( SubDir.Name.Length - 1 ) ) );
- }
- else
- {
- Versions.Add( Path.GetFileName( SubDir.Name ) );
- }
- }
- }
- foreach ( string Ver in Versions )
- {
- cboVersion.Items.Add( Ver );
- }
- cboVersion.SelectedIndex = 0;
- LoadScripts();
- }
- private void LoadScripts()
- {
- foreach ( string Version in Versions )
- {
- List<Aspect> AspectList = new List<Aspect>();
- foreach ( string Script in Directory.GetFiles( ScriptsDir + Version + "\\" ) )
- {
- FileStream stream = File.Open( Script, FileMode.Open );
- BinaryFormatter formatter = new BinaryFormatter();
- Aspect aspect = ( Aspect ) formatter.Deserialize( stream );
- AspectList.Add( aspect );
- }
- Aspects.Add( Version, AspectList );
- }
- }
- private void LoadStateData()
- {
- if ( File.Exists( AppData ) == true )
- {
- FileStream stream = File.Open( AppData, FileMode.Open );
- BinaryFormatter formatter = new BinaryFormatter();
- this.AppState = ( AppStateData ) formatter.Deserialize( stream );
- stream.Close();
- }
- else
- {
- SaveStateData();
- }
- }
- private void SaveStateData()
- {
- FileStream stream = File.Open( AppData, FileMode.OpenOrCreate );
- BinaryFormatter formatter = new BinaryFormatter();
- formatter.Serialize( stream, this.AppState );
- stream.Close();
- }
- private void frmMain_Load( object sender, EventArgs e )
- {
- FindScripts();
- LoadStateData();
- }
- private void aboutToolStripMenuItem_Click( object sender, EventArgs e )
- {
- new frmAbout().Show();
- }
- private void MouseWheelScrollHandler( object sender, MouseEventArgs e )
- {
- NumericUpDown Ctrl = ( NumericUpDown ) sender;
- HandledMouseEventArgs HandledArgs = e as HandledMouseEventArgs;
- HandledArgs.Handled = true;
- decimal Value = Ctrl.Value + ( ( e.Delta > 0 ) ? Ctrl.Increment : -Ctrl.Increment );
- Ctrl.Value = Math.Max( Ctrl.Minimum, Math.Min( Value, Ctrl.Maximum ) );
- }
- private void cboVersion_SelectedIndexChanged( object sender, EventArgs e )
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement