public Form1() { InitializeComponent(); FormClosed += Form1_FormClosed; //Set ComboBox foreach (MaskingFormat f in (MaskingFormat[])Enum.GetValues(typeof(MaskingFormat))) { comboBox_maskFormat.Items.Add(f.ToString()); } foreach (SpacingCharacter c in (SpacingCharacter[])Enum.GetValues(typeof(SpacingCharacter))) { comboBox_spacingChar.Items.Add(c.ToString()); } Initialize(); //Load config ClDeviceIndex targetDeviceIndex = ConfigManager.LoadConfig(CONFIG_FILENAME); if (targetDeviceIndex.Platform == -1 || targetDeviceIndex.Device == -1) { //Reset config if config is missing ConfigManager.RemoveConfig(CONFIG_FILENAME); targetDeviceIndex = ConfigManager.LoadConfig(CONFIG_FILENAME); } //Validate device if (!ClDeviceManager.ValidateDevice(targetDeviceIndex)) { //Reset config if config is not valid ConfigManager.RemoveConfig(CONFIG_FILENAME); targetDeviceIndex = ConfigManager.LoadConfig(CONFIG_FILENAME); //If device is not valide, force close. if (!ClDeviceManager.ValidateDevice(targetDeviceIndex)) { MessageBox.Show("Target device is not valid." + Environment.NewLine + "Check config.cfg and try other options."); this.Load += (s, e) => Close(); } } //Setup OpenCL device imageProcessor = new ImageProcessor(targetDeviceIndex, LoadProgramText()); if (!imageProcessor.IsReady) { this.Load += (s, e) => Close(); } }
//Create platform and device list text file. private static void CreateDefaultConfig(string fileName) { try { using (StreamWriter writer = new StreamWriter(fileName)) { //Get platform list string[] platform = ClDeviceManager.GetNullablePlatformNameList(); if (platform == null) { writer.WriteLine("//This program is not available on this platform."); return; } //Write platform for (int i = 0; i < platform.Length; i++) { writer.WriteLine("//" + (i + 1) + "." + platform[i]); //Write each device in platform int index = 1; string[] device = ClDeviceManager.GetNullableDeviceNameList(index - 1); if (device == null) { break; } foreach (string d in device) { writer.WriteLine("//\t" + index + "." + d); index++; } writer.WriteLine("//"); } //Create default config writer.WriteLine("//The MAC address verifies that the config was created by this computer."); writer.WriteLine("//0 for default program settings."); writer.WriteLine("MAC = " + GetMacAddress()); writer.WriteLine("Platform = 0"); writer.WriteLine("DeviceNumber = 0"); } } catch (Exception e) { throw e; } }