@@ -28,14 +28,10 @@ struct PathFileStruct {
2828};
2929
3030GtkWidget * progress_bar ;
31- GtkWidget * button ;
3231GtkWidget * window ;
3332
34- //Thread
35- pthread_t thread ;
36- int thread_running = 0 ;
37-
3833CURL * new_handle ;
34+ char currentFile [255 ] = "None" ;
3935
4036uint16_t bswap_16 (uint16_t value )
4137{
@@ -56,7 +52,11 @@ void progress_func(void *p, double dltotal, double dlnow, double ultotal, double
5652 dlnow = 1 ;
5753 GtkProgressBar * progress_bar = (GtkProgressBar * )p ;
5854
55+ char downloadString [255 ] = "Downloading " ;
56+ strcat (downloadString , currentFile );
57+
5958 gtk_progress_bar_set_fraction (progress_bar , dlnow /dltotal );
59+ gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress_bar ), downloadString );
6060 // force redraw
6161 while (gtk_events_pending ())
6262 gtk_main_iteration ();
@@ -117,17 +117,14 @@ int download_file(gpointer progress)
117117}
118118
119119void * progressDialog () {
120- GtkWidget * window ;
121- GtkWidget * progress ;
122-
123120 gtk_init (NULL , NULL );
124121
125122 //Create window
126123 window = gtk_window_new (GTK_WINDOW_TOPLEVEL );
127- gtk_window_set_title (GTK_WINDOW (window ), "LibCurl Download Progress Bar " );
124+ gtk_window_set_title (GTK_WINDOW (window ), "Download Progress" );
128125 gtk_window_set_default_size (GTK_WINDOW (window ), 300 , 50 );
129126 gtk_container_set_border_width (GTK_CONTAINER (window ), 10 );
130- //g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit ), NULL );
127+ gtk_window_set_modal ( GTK_WINDOW ( window ), TRUE );
131128
132129 //Create progress bar
133130 progress_bar = gtk_progress_bar_new ();
@@ -140,10 +137,6 @@ void *progressDialog() {
140137 gtk_box_pack_start (GTK_BOX (main_box ), progress_bar , FALSE, FALSE, 0 );
141138
142139 gtk_widget_show_all (window );
143-
144- download_file (progress_bar );
145-
146- gtk_widget_destroy (GTK_WIDGET (window ));
147140}
148141
149142int downloadFile (char * download_url , char * output_path ) {
@@ -169,7 +162,7 @@ int downloadFile(char *download_url, char *output_path) {
169162 struct_to_save -> file_pointer = output_file ;
170163 curl_easy_setopt (new_handle , CURLOPT_WRITEDATA , output_file );
171164 curl_easy_setopt (new_handle , CURLOPT_PRIVATE , struct_to_save );
172- progressDialog ( );
165+ download_file ( progress_bar );
173166 return 0 ;
174167}
175168
@@ -275,6 +268,7 @@ int downloadTitle(const char *titleID) {
275268 content_count = bswap_16 (content_count );
276269
277270 // Add all needed curl handles to the multi handle
271+ progressDialog ();
278272 for (int i = 0 ; i < content_count ; i ++ ) {
279273 int offset = 2820 + (48 * i );
280274 uint32_t id ; // the id should usually be chronological, but we wanna be sure
@@ -284,12 +278,14 @@ int downloadTitle(const char *titleID) {
284278 // add a curl handle for the content file (.app file)
285279 snprintf (output_path , sizeof (output_path ), "%s/%08X.app" , output_dir , id );
286280 snprintf (download_url , 78 , "%s/%08X" , base_url , id );
281+ sprintf (currentFile , "%08X.app" , id );
287282 downloadFile (download_url , output_path );
288283
289284 if ((tmd_data .memory [offset + 7 ] & 0x2 ) == 2 ) {
290285 // add a curl handle for the hash file (.h3 file)
291286 snprintf (output_path , sizeof (output_path ), "%s/%08X.h3" , output_dir , id );
292287 snprintf (download_url , 81 , "%s/%08X.h3" , base_url , id );
288+ sprintf (currentFile , "%08X.h3" , id );
293289 downloadFile (download_url , output_path );
294290 }
295291 }
@@ -298,6 +294,7 @@ int downloadTitle(const char *titleID) {
298294 printf ("Downloading all files for TitleID %s done...\n" , titleID );
299295
300296 // cleanup curl stuff
297+ gtk_widget_destroy (GTK_WIDGET (window ));
301298 curl_global_cleanup ();
302299 free (output_dir );
303300}
0 commit comments