Ciao ragazzi! Qualcuno sa aiutarmi su un programma(aggiornamento automatico con SFML) scritto per console da trasformarlo in GUI? Il programma(funzionante) e' questo:
#include <SFML/Window.hpp>
#include <SFML/Network.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <windows.h>
#include <fstream>
#include <direct.h>
#include <stdlib.h>
using namespace std;
int main()
{
int Cy, Cz;
Cy = 0;
Cz = 0;
string username, password, res1, accountsaved;
bool SFU;// Search For Update
SFU = false;
sf::Font systemFont;
if (!systemFont.loadFromFile("Bin/System.ttf"))
{
cout <<"Error..."<< endl;
}
sf::Text mConnected;
mConnected.setFont(systemFont);
mConnected.setString("Connected.");
mConnected.setColor(sf::Color::White);
mConnected.setCharacterSize(14);
sf::Text mLogin1;
mLogin1.setFont(systemFont);
mLogin1.setString("There's an account saved. Do you want to load it?");
mLogin1.setColor(sf::Color::White);
mLogin1.setCharacterSize(14);
sf::RenderWindow window(sf::VideoMode(1250, 860), "Multiverse");
window.setFramerateLimit(84);
while (window.isOpen())
{
sf::Event event_close;
while (window.pollEvent(event_close))
{
if (event_close.type == sf::Event::Closed)
window.close();
}
window.clear();
sf::Ftp MultiverseServerFTP;
sf::Ftp::Response responseConnections = MultiverseServerFTP.connect("Ip del server");
while (SFU == false)
{
if (responseConnections.isOk())
{
mConnected.setPosition(Cy, Cz);
window.draw(mConnected);
cout <<"Connected."<< endl;
}
else
{
cout <<"Not connected, error..."<< endl;
cout << "Response status: " << responseConnections.getStatus() << endl;
system ("PAUSE");
return 0;
}
ifstream StaffAccount("Saves/StaffAccount.txt");
if (!StaffAccount)
{
cout <<"Insert the username for the login."<< endl;
cin >>username;
cout <<"Insert the password for the login."<< endl;
cin >>password;
cout <<"Do you want to save the username and pass?"<< endl;
cin >>res1;
while (res1 != "No" && res1 != "no" && res1 != "NO" && res1 != "Yes" && res1 != "yes" && res1 != "YES")
{
cout <<"Say Yes or No."<< endl;
cin >>res1;
}
if (res1 == "Yes"||res1 == "yes"||res1 == "YES")
{
CreateDirectory("Saves", NULL);
ofstream StaffAccount ("Saves/StaffAccount.txt");
StaffAccount <<username + " " + password;
StaffAccount.close();
}
else
{
cout <<"Ok."<< endl;
}
}
else
{
mLogin1.setPosition(Cy, Cz + 25);
window.draw(mLogin1);
window.clean(mLogin1);
window.display();
cout <<"There's an account saved. Do you want to load it?"<< endl;
cin >>res1;
while (res1 != "No" && res1 != "no" && res1 != "NO" && res1 != "Yes" && res1 != "yes" && res1 != "YES")
{
cout <<"Say Yes or No."<< endl;
cin >>res1;
}
if (res1 == "Yes"||res1 == "yes"||res1 == "YES")
{
ifstream StaffAccount("Saves/StaffAccount.txt");
StaffAccount >> username >> password;
}
else
{
cout <<"Insert the username for the login."<< endl;
cin >>username;
cout <<"Insert the password for the login."<< endl;
cin >>password;
cout <<"Do you want to save the username and pass?"<< endl;
cin >>res1;
while (res1 != "No" && res1 != "no" && res1 != "NO" && res1 != "Yes" && res1 != "yes" && res1 != "YES")
{
cout <<"Say Yes or No."<< endl;
cin >>res1;
}
if (res1 == "Yes"||res1 == "yes"||res1 == "YES")
{
CreateDirectory("Saves", NULL);
ofstream StaffAccount ("Saves/StaffAccount");
StaffAccount <<username + " " + password;
}
else
{
cout <<"Ok."<< endl;
}
}
}
sf::Ftp::Response responseLogin = MultiverseServerFTP.login(username, password);
if (responseLogin.isOk())
{
cout <<"Logged."<< endl;
MultiverseServerFTP.changeDirectory("/public_html/Staff");
sf::Ftp::Response responseDownloadFinished = MultiverseServerFTP.download("Version.txt", "Version");
if (responseDownloadFinished.isOk())
{
cout <<"Download of version completed."<< endl;
}
else
{
cout <<"Failed to download the version file. Error:"<< responseDownloadFinished.getStatus()<< endl;
CreateDirectory("Version", NULL);
sf::Ftp::Response responseDownloadFinished = MultiverseServerFTP.download("Version.txt", "Version");
if (responseDownloadFinished.isOk())
{
cout <<"Download of version completed."<< endl;
}
}
sf::Ftp::Response responseDownloadFinished1 = MultiverseServerFTP.download("Multiverse_updater.exe", "");
if (responseDownloadFinished1.isOk())
{
cout <<"Download of Multiverse updater completed."<< endl;
}
else
{
cout <<"Failed to download Multiverse updater. Error:"<< responseDownloadFinished1.getStatus()<< endl;
}
string version1;
string version2;
ifstream versiontxt("Version/Version.txt");
ifstream versionsaved("Saves/Version.txt");
if(!versionsaved)
{
cout<<"Error: Couldn't load the file! Starting the process for create it now."<< endl;
ofstream versionsaved("Saves/Version.txt");
}
getline(versiontxt, version1);
getline(versionsaved, version2);
if (version1 != version2)
{
cout <<"The program need a update. Starting the process for update it."<< endl;
Sleep(3000);
MultiverseServerFTP.disconnect();
system ("Multiverse_updater.exe");
return 0;
}
else
{
cout <<"All files are up-to-date."<< endl;
SFU = true;
}
}
else
{
cout <<"Not logged, error..."<< endl;
cout << "Response status: " << responseLogin.getStatus() << endl;
}
}
window.display();
}
return 0;
}
Come potete vedere stavo gia' provando a convertire alcune scritte.
Non vi sto chiedendo di rifarmi il programma, ma di consigliarmi e aiutarmi per i problemi che ho(e avrò)...
Alcuni problemi:
L'apparizione delle scritte nello schermo(window.draw(nometesto);) perche' sparisce quando scrivo 2 volte window.display() ? Esempio
//[...]
if(responseconnection.isOk) {
window.draw(testo1);
//altri comandi
if (!filesalvato){
window.draw(testo2); //ovviamente imposto la posizione di questa scritta piu' in basso
window.display(); //Quando passa a windw.display cancella(o nasconde)la scritta precedente!
}
}
//[...]
Oppure... Qua le scritte sono dichiarate in 5 righe, c'è un modo piu' veloce per dichiararle? Ne conosco un'altro(non usato qua), ma sempre di 2 righe...
sf::text testo(stringa, font, grandezza(es.20));
testo.setColor(sf::Color::White);
Grazie ragazzi, spero di risolvere il problema