1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
String^ fileContent = gcnew String("");
String^ filePath = gcnew String("");
openFileDialog1->InitialDirectory = Environment::CurrentDirectory;
openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1->FilterIndex = 2;
openFileDialog1->RestoreDirectory = true;
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
//Get the path of the user configuration file for SimVars
filePath = openFileDialog1->FileName;
String^ filePathSimVars = IO::Path::GetFullPath(Environment::CurrentDirectory+"/Data/SimVars.txt");
System::IO::FileStream^ fsvars = gcnew System::IO::FileStream(filePathSimVars, System::IO::FileMode::Open, System::IO::FileAccess::Read);
System::IO::StreamReader^ srvars = gcnew System::IO::StreamReader(fsvars, System::Text::Encoding::UTF8);
String^ contentSimVars = srvars->ReadToEnd();
String^ filePathSimUnits = IO::Path::GetFullPath(Environment::CurrentDirectory + "/Data/SimUnits.txt");
System::IO::FileStream^ fsunits = gcnew System::IO::FileStream(filePathSimUnits, System::IO::FileMode::Open, System::IO::FileAccess::Read);
System::IO::StreamReader^ srunits = gcnew System::IO::StreamReader(fsunits, System::Text::Encoding::UTF8);
String^ contentSimUnits = srunits->ReadToEnd();
cli::array<String^>^ aLines = System::IO::File::ReadAllLines(filePath);
for (uint32_t i = 0; i < aLines->Length; ++i) {
cli::array<String^>^ aSubStrings = aLines[i]->Split(',');
if (aSubStrings->Length == 3) {
bool first = false, second = false;
int result = contentSimVars->IndexOf(aSubStrings[0], 0, contentSimVars->Length);
if (result >= 0) //Found
first = true;
result = contentSimUnits->IndexOf(aSubStrings[1], 0, contentSimUnits->Length);
if (result >= 0) //Found
second = true;
int third = Convert::ToInt16(aSubStrings[2]);
if ((first) && (second)) {
SimRecs.push_back(gcnew SimConnectVars(aSubStrings[0], aSubStrings[1], third));
}
else
{
// Initializes the variables to pass to the MessageBox.Show method.
String^ message = "Wrong SimVar or Unit: Line ?" + i;
String^ caption = "Error in SimVar file";
MessageBoxButtons buttons = MessageBoxButtons(); //OK only
// Displays the MessageBox.
MessageBox::Show(message, caption, buttons);
}
}
else if (aSubStrings->Length <3) { //FIXME
// Initializes the variables to pass to the MessageBox.Show method.
String^ message = "Too few items in a line: " + i;
String^ caption = "Error in SimVar file";
MessageBoxButtons buttons = MessageBoxButtons(); //OK only
// Displays the MessageBox.
MessageBox::Show(message, caption, buttons);
}
}
load_SimRecs();
}
}
|