@@ -142,20 +142,25 @@ class client {
142142
143143 void reg () {
144144 char buffer[1024 ];
145+ bool ok;
145146 do {
146147 clear ();
147148 printw (" Sign Up\n Enter Username: " );
148149 getstr (buffer);
149150 sock.send (buffer);
150- } while (sock.recv () != " ok" );
151+ if ((ok = sock.recv () != " ok" ))
152+ ui.notification (" Kurwa" , {" This username is already in use." });
153+ } while (ok);
151154 printw (" Enter Password: " );
152155 getstr (buffer);
153156 sock.send (buffer);
154157 clear ();
158+ ui.notification (" Success!" , {" You have registered a new account." });
155159 }
156160
157161 void log () {
158162 char buffer[1024 ];
163+ bool ok;
159164 do {
160165 printw (" Sign In\n Enter Username: " );
161166 getstr (buffer);
@@ -164,7 +169,11 @@ class client {
164169 getstr (buffer);
165170 sock.send (buffer);
166171 clear ();
167- } while (sock.recv () != " ok" );
172+ if ((ok = sock.recv () != " ok" ))
173+ ui.notification (" Kurwa" ,
174+ {" The password or username is incorrect." });
175+ } while (ok);
176+ ui.notification (" Success!" , {" You signed in to your account." });
168177 }
169178 client (SSL* ssl, clsUi& ui) : sock(ssl), ui(ui) {}
170179};
@@ -209,8 +218,7 @@ class project {
209218 owner.sock .send (" removeDir " + path + it.key ());
210219 owner.sock .send (" createFile " + path + it.key ());
211220 if (owner.sock .recv () == " ok" )
212- owner.sock .sendFile (prjPath + path + it.key (),
213- &progressBar);
221+ owner.sock .sendFile (prjPath + path + it.key ());
214222 } else if (newjs[it.key ()].is_object ()) {
215223 compJson (it.value (), newjs[it.key ()],
216224 path + it.key () + ' /' );
@@ -219,8 +227,7 @@ class project {
219227 it.key ().c_str ());
220228 owner.sock .send (" createFile " + path + it.key ());
221229 if (owner.sock .recv () == " ok" )
222- owner.sock .sendFile (prjPath + path + it.key (),
223- &progressBar);
230+ owner.sock .sendFile (prjPath + path + it.key ());
224231 }
225232 } else {
226233 if (it.value ().is_object () || it.value ().is_null ()) {
@@ -247,8 +254,7 @@ class project {
247254 it.key ().c_str ());
248255 owner.sock .send (" createFile " + path + it.key ());
249256 if (owner.sock .recv () == " ok" )
250- owner.sock .sendFile (prjPath + path + it.key (),
251- &progressBar);
257+ owner.sock .sendFile (prjPath + path + it.key ());
252258 }
253259 }
254260 }
@@ -261,19 +267,24 @@ class project {
261267
262268 void set () {
263269 char buffer[1024 ];
264- /* do {
270+ bool ok;
271+ do {
265272 printw (" Path to your project: " );
266273 getstr (buffer);
267274 prjPath = buffer;
268- } while (!fs::exists(prjPath) && !fs::is_directory(prjPath)); */
269- prjPath = " /home/jomm/Documents/kurwa/client/test/" ;
270- // prjPath += '/';
275+ if ((ok = !fs::exists (prjPath) && !fs::is_directory (prjPath)))
276+ owner.ui .notification (" kurwa" , {" Path is invalid." });
277+ } while (ok);
278+ prjPath += ' /' ;
279+ // prjPath = "/home/jomm/Documents/kurwa/client/test/";
271280 do {
272281 printw (" Name of your project: " );
273282 getstr (buffer);
274283 prjName = buffer;
275284 owner.sock .send (prjName);
276- } while (owner.sock .recv () != " ok" );
285+ if ((ok = owner.sock .recv () != " ok" ))
286+ owner.ui .notification (" Kurwa" , {" Project name is invalid." });
287+ } while (ok);
277288 clear ();
278289 }
279290 void open () {
@@ -287,11 +298,12 @@ class project {
287298 json check = genJson (prjPath);
288299 compJson (curr, check, " " );
289300 owner.sock .send (check.dump ());
290- } else if (!strcmp (buffer, " quit " )) {
291- owner.sock .send (" quit " );
301+ } else if (!strcmp (buffer, " back " )) {
302+ owner.sock .send (" back " );
292303 break ;
293304 }
294305 }
306+ clear ();
295307 }
296308 void download () {
297309 string command;
@@ -303,7 +315,7 @@ class project {
303315 fs::create_directory (prjPath + path);
304316 } else if (action == " createFile" ) {
305317 printw (" File %s was created\n " , path.c_str ());
306- owner.sock .recvFile (prjPath + path, &progressBar );
318+ owner.sock .recvFile (prjPath + path);
307319 }
308320 }
309321 }
@@ -338,29 +350,33 @@ int main(int argc, char* argv[]) {
338350 client.log ();
339351 break ;
340352 }
341- project project (client);
342- switch (ui.menu (" Choose one option:" ,
343- {" Create new project" , " Open existing project" ,
344- " Download project from server" })) {
345- case 0 :
346- client.sock .send (" createPrj" );
347- project.set ();
348- project.open ();
349- break ;
350- case 1 :
351- client.sock .send (" openPrj" );
352- project.set ();
353- project.open ();
354- break ;
355- case 2 :
356- client.sock .send (" downloadPrj" );
357- project.set ();
358- project.download ();
359- project.open ();
360- break ;
353+ while (true ) {
354+ project project (client);
355+ switch (ui.menu (" Choose one option:" ,
356+ {" Create new project" , " Open existing project" ,
357+ " Download project from server" , " Exit" })) {
358+ case 0 :
359+ client.sock .send (" createPrj" );
360+ project.set ();
361+ project.open ();
362+ break ;
363+ case 1 :
364+ client.sock .send (" openPrj" );
365+ project.set ();
366+ project.open ();
367+ break ;
368+ case 2 :
369+ client.sock .send (" downloadPrj" );
370+ project.set ();
371+ project.download ();
372+ project.open ();
373+ break ;
374+ case 3 :
375+ client.sock .send (" quit" );
376+ endwin ();
377+ SSL_CTX_free (ctx);
378+ client.sock .close ();
379+ return 0 ;
380+ }
361381 }
362- endwin ();
363-
364- SSL_CTX_free (ctx);
365- client.sock .close ();
366382}
0 commit comments