private static bool DoSetup() { ConnectionInfo ci = null; Weebox = new WeeboxSync(); int state = 1; bool cont = true; FicheiroSystemAbstraction fsa = new FicheiroSystemAbstraction(); WelcomeScreen ws = new WelcomeScreen (); ws.ShowDialog (); do { /** * if dialog results are DialogResult.Retry, * show the last form (back button was pressed) * if the result is Cancel, setup is to be canceled entirely * if the result is OK, follow to the next form, up until download. */ DialogResult result; switch (state) { case 1: ci = new ConnectionInfo(); ConnectionInfoEditor cie = new ConnectionInfoEditor (ref ci); result = cie.ShowDialog (); if (result == DialogResult.Cancel) return false; if(result == DialogResult.Retry) state = 0; // exit else state++; break; case 2: if(ci == null) { state = 0; break; } Weebox.connection_info = ci; LoginWindow lw = new LoginWindow ( ref Weebox); result = lw.ShowDialog (); if (result == DialogResult.Cancel) return false; if(result == DialogResult.Retry) state--; // back to previous dialog else state++; // next dialog break; case 3: FolderChooser fc = new FolderChooser (ref Weebox); result = fc.ShowDialog (); if (result == DialogResult.Cancel) return false; if (result == DialogResult.Retry) state--; // back to previous dialog else state++; // next dialog break; case 4: //setup successful, go to download SaveRegistryKeys (); DataBaseAbstraction dba = new DataBaseAbstraction (); try { dba.SaveConnectionInfo(Weebox.connection_info); } catch (Exception e) { //eliminar chaves de registo DeleteRegistryKeys(); //eliminar pasta root fsa.DeleteRecursiveFolder(Weebox.getRootFolder()); MessageBox.Show( "Setup falhou. Por favor inicie novamente a aplicação, verifique os dados inseridos e tente novamente", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } DownloadWait dw = new DownloadWait (ref Weebox); var res = dw.ShowDialog (); if(res == DialogResult.Cancel) { //eliminar chaves de registo DeleteRegistryKeys(); //eliminar pasta root fsa.DeleteRecursiveFolder(Weebox.getRootFolder()); MessageBox.Show( "Setup falhou. Por favor inicie novamente a aplicação, verifique os dados inseridos e tente novamente", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } else if (res == DialogResult.OK) { MessageBox.Show ("O setup foi concluído com sucesso.\nBem-vindo ao mundo Weebox.", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information); } cont = false; break; case 5: // all tasks done, exit return true; case 0: //Cancel setup and exit application Application.Exit (); return false; default: MessageBox.Show ( "Houve um erro no processo de instalação.\n" + "Por favor volte a iniciar a aplicação para concluir o processo,", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); //eliminar chaves de registo DeleteRegistryKeys(); //eliminar pasta root fsa.DeleteRecursiveFolder(Weebox.getRootFolder()); Application.Exit(); break; } } while (cont); //MessageBox.Show ("Setup done!, Now we rock!"); return true; }
private void SetUserCredentials(object sender, EventArgs eventArgs) { WeeboxSync ws = new WeeboxSync (); LoginWindow lw = new LoginWindow(ref ws); var dialogRes = lw.ShowDialog(); if (dialogRes == DialogResult.OK) { //nao foi cancelado var res = weebox.setCredentials (ws.connection_info.user.user, ws.connection_info.user.pass); if (!res) { MessageBox.Show ("Sincronização em curso, por favor aguarde alguns minutos e tente novamente.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }