/// <summary> /// Initializes main IronPythonEngine and loads pswrdgen.py variables /// </summary> private void bootstrap() { try { //Let check and make sure the user has Python24 if (!Directory.Exists("C:\\Python24\\Lib")) { DialogResult dResult = MessageBox.Show("C:\\Python24\\Lib not found.\r\npswrdgeniron needs Python24 to run. Do you want to download Python24?", "Python 2.4 Not Found", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dResult == DialogResult.Yes) { System.Diagnostics.Process.Start(@"http://www.python.org/download/releases/2.4.4/"); } else { return; } } //Start importing pswrdgen.py to IronPython pe.ExecuteCommand("import sys"); pe.AddToPath("C:\\Python24\\Lib"); pe.AddToPath(Application.StartupPath);//add the windows installation path so no errors when using shortcuts pe.ExecuteCommand("import os"); pe.ExecuteCommand("import pswrdgen"); pe.ExecuteCommand("i = pswrdgen.pswrdgen()"); //Get version number of current file currentversion = pe.EvaluateAs <string>("pswrdgen.__version__"); //Get url string url = pe.EvaluateAs <string>("pswrdgen.__url__"); //Display some info to user... tbDisplay.AppendText("*************************************************************************\r\n"); tbDisplay.AppendText("pswrdgeniron: " + url + "\r\npswrdgen.py version " + currentversion + " on \r\n" + pe.VersionString + "\r\n"); tbDisplay.AppendText(pe.EvaluateAs <string>(@"pswrdgen.__doc__") + "\r\n"); tbDisplay.AppendText("*************************************************************************\r\n"); //Get the pswrdgen.py defaults values and assign them to the C# equivalent variables SWAPS = (PythonDictionary)pe.EvaluateAs <PythonDictionary>("i.SWAPS").Clone(); MINLENGTH = (int)pe.EvaluateAs <object>("i.MINLENGTH"); MAXLENGTH = (int)pe.EvaluateAs <object>("i.MAXLENGTH"); CAPLENGTH = (int)pe.EvaluateAs <object>("i.CAPLENGTH"); GENCOUNT = (int)pe.EvaluateAs <object>("i.GENCOUNT"); ADDCHAR = (string)pe.EvaluateAs <object>("i.ADDCHAR"); ADDCOUNT = (int)pe.EvaluateAs <object>("i.ADDCOUNT"); WORDFILELISTS = (List)pe.EvaluateAs <List>("i.WORDFILELISTS"); //*** Update the controls to display to user //Display the current SWAP PythonDictionary ruleset tbSwapSet.Text = SWAPS.ToString(); //Display the current ADDCHAR ruleset tbInsertionChars.Text = ADDCHAR; //Update cbMinLength and the Event will update cbMaxLength and cbCaps int numbers = 3; if (MINLENGTH <= MAXLENGTH) { //Populate the choices for MinLength while (numbers <= 25) { cbMinLength.Items.Add(numbers); numbers = numbers + 1; } cbMinLength.SelectedItem = MINLENGTH; cbMaxLength.SelectedItem = MAXLENGTH; cbCaps.SelectedItem = CAPLENGTH; //Populate the choices for MinLength numbers = 1; while (numbers <= 101) { cbGencount.Items.Add(numbers); numbers = numbers + 1; } cbGencount.SelectedItem = GENCOUNT; //Populate the choices for AddCount numbers = 0; while (numbers <= 40) { cdAddCount.Items.Add(numbers); numbers = numbers + 1; } cdAddCount.SelectedItem = ADDCOUNT; //Make bUpdate button enabled false since their were no changes // this must be done after its data population bUpdate.Enabled = false; bSavesettings.Enabled = false; } else { MessageBox.Show("MINLENGTH > MAXLENGTH ; Can not populate cbMinLength"); } //update the file list combobox IEnumerator listenum = WORDFILELISTS.GetEnumerator(); while (listenum.MoveNext()) { cbWordFiles.Items.Add(listenum.Current); } cbWordFiles.SelectedIndex = 0; } catch (Exception ex) { MessageBox.Show("bootstrap error:\r\n" + ex.Message + "\r\n" + ex.InnerException); } }