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
| private: System::Void BoutonEnregistrer_Click(System::Object^ sender, System::EventArgs^ e) {
//SAVE CURRENT FILE
this->ProgressBar1->Value = 22;
this->TexteStatutVAR->Text = "Création du fichier de sauvegarde...";
Application::DoEvents();
if (this->FileNameBox->Text == "")
{
this->FileNameBox->Text = "Untitled";
BOOL MessageBeep(MB_ICONEXCLAMATION);
MessageBox::Show("Vous n'aviez pas précisé de nom pour votre fichier. Par défaut, il a été nommé 'Untitled'.", "Information", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
if (this->PathNameBox->Text == "")
{
this->PathNameBox->Text = "Redacted triggers\\\\";
BOOL MessageBeep(MB_ICONEXCLAMATION);
MessageBox::Show("Vous n'aviez pas précisé de dossier où stocker votre fichier. Par défaut, \nle fichier va être enregistré dans \\Redacted triggers\\ (présent dans le dossier d'installation du programme).", "Information", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
//First settings
System::String ^PathNameS, ^FileNameS, ^MyFileS;
PathNameS = this->PathNameBox->Text;
FileNameS = this->FileNameBox->Text;
MyFileS = (PathNameS + FileNameS + ".trig");
//Variables and Other
FILE *fichier1;
//Store Current text
System::String ^Text2SaveSTRING = this->TriggersRedactionSpace->Text;
this->ProgressBar1->Value = 45;
this->TexteStatutVAR->Text = "Enregistrement des informations...";
Application::DoEvents();
//Convert in usable characters table
char *Text2Save = static_cast<char *>(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(Text2SaveSTRING).ToPointer());
char *MyFile = static_cast<char *>(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(MyFileS).ToPointer());
//Open Save Dialog
//Open file to put stored text in it /--\ CHANGE "FILENAME" !
fichier1 = fopen(MyFile, "w");
this->ProgressBar1->Value = 75;
this->TexteStatutVAR->Text = "Ouverture du fichier...";
Application::DoEvents();
//If the file exist, re-write over it the stored text
if(is_readable(MyFile))
{
this->ProgressBar1->Value = 100;
this->TexteStatutVAR->Text = "Écriture du fichier *.trig...";
Application::DoEvents();
fprintf(fichier1, Text2Save);
fclose(fichier1);
}
else
{
this->ProgressBar1->Value = 0;
this->TexteStatutVAR->Text = "Erreur lors de la vérification !";
Application::DoEvents();
BOOL MessageBeep(MB_ICONEXCLAMATION);
System::Windows::Forms::MessageBox::Show("Erreur lors du test de l'ouverture du fichier. La procédure de sauvegarde a été annulée : veuillez recommencer.\nSi l'erreur persiste, le mieux est de créer manuellement un fichier .txt où vous copiez-collez votre code.", "Sauvegarde non effectuée", MessageBoxButtons::OK, MessageBoxIcon::Warning);
}
//Clean memory
System::Runtime::InteropServices::Marshal::FreeHGlobal(safe_cast<IntPtr>(Text2Save));
//END SAVE CURRENT FILE
this->ProgressBar1->Value = 0;
this->TexteStatutVAR->Text = "Fichier enregistré avec succès !";
Application::DoEvents();
System::Threading::Thread::Sleep(2000);
this->TexteStatutVAR->Text = "Prêt";
Application::DoEvents();
} |
Partager