GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a tiny graphical app kit for ruby
Homepage: http://code.whytheluckystiff.net/shoes
Clone URL: git://github.com/why/shoes.git
 * shoes/http/winhttp.c: close the file handle before the completion 
 event.
 * shoes/ruby.c: use `rename` instead of a ruby call.
why (author)
Fri Jul 25 10:58:47 -0700 2008
commit  999c47ecd4612e77761f5f627406b97f2495de87
tree    e37621be3da30c92a02ffeb36da0c5dc202f3e28
parent  cca85b7b052e04698346515c890a3027d4d629e3
...
30
31
32
33
34
35
36
37
...
156
157
158
 
 
 
 
 
 
159
160
161
...
168
169
170
 
 
 
171
172
173
...
187
188
189
 
 
 
 
 
 
...
30
31
32
 
 
33
34
35
...
154
155
156
157
158
159
160
161
162
163
164
165
...
172
173
174
175
176
177
178
179
180
...
194
195
196
197
198
199
200
201
202
0
@@ -30,8 +30,6 @@ shoes_download(shoes_download_request *req)
0
       FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
0
   shoes_winhttp(_host, _port, _path, req->mem, file, &_size, req->handler, req->data);
0
   req->size = _size;
0
- if (file != INVALID_HANDLE_VALUE)
0
- CloseHandle(file);
0
 }
0
 
0
 DWORD WINAPI
0
@@ -156,6 +154,12 @@ shoes_winhttp(LPCWSTR host, INTERNET_PORT port, LPCWSTR path, TCHAR *mem, HANDLE
0
     }
0
   }
0
 
0
+ if (file != INVALID_HANDLE_VALUE)
0
+ {
0
+ CloseHandle(file);
0
+ file = INVALID_HANDLE_VALUE;
0
+ }
0
+
0
   HTTP_EVENT(handler, SHOES_HTTP_COMPLETED, last, 100, *size, *size, data, mem, goto done);
0
   complete = 1;
0
 
0
@@ -168,6 +172,9 @@ done:
0
     if (handler != NULL) handler(&event, data);
0
   }
0
 
0
+ if (file != INVALID_HANDLE_VALUE)
0
+ CloseHandle(file);
0
+
0
   if (req)
0
     WinHttpCloseHandle(req);
0
 
0
@@ -187,3 +194,9 @@ shoes_http_error(SHOES_DOWNLOAD_ERROR code)
0
   msg[msglen] = '\0';
0
   return rb_str_new2(msg);
0
 }
0
+
0
+SHOES_DOWNLOAD_HEADERS
0
+shoes_http_headers(VALUE hsh)
0
+{
0
+ return NULL;
0
+}
...
178
179
180
181
 
182
183
184
185
186
 
187
188
189
...
235
236
237
238
 
239
240
241
...
414
415
416
417
 
418
419
420
421
422
 
423
424
425
...
427
428
429
430
 
431
432
433
...
451
452
453
454
 
455
456
457
...
468
469
470
471
 
472
473
474
...
496
497
498
499
 
500
501
502
...
596
597
598
599
 
600
601
602
603
604
605
 
606
607
608
...
614
615
616
617
 
618
619
620
...
624
625
626
627
 
628
629
630
...
634
635
636
637
 
638
639
640
...
653
654
655
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656
657
658
...
718
719
720
721
 
722
723
724
...
733
734
735
 
736
737
738
...
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
...
178
179
180
 
181
182
183
184
185
 
186
187
188
189
...
235
236
237
 
238
239
240
241
...
414
415
416
 
417
418
419
420
421
 
422
423
424
425
...
427
428
429
 
430
431
432
433
...
451
452
453
 
454
455
456
457
...
468
469
470
 
471
472
473
474
...
496
497
498
 
499
500
501
502
...
596
597
598
 
599
600
601
602
603
604
 
605
606
607
608
...
614
615
616
 
617
618
619
620
...
624
625
626
 
627
628
629
630
...
634
635
636
 
637
638
639
640
...
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
...
736
737
738
 
739
740
741
742
...
751
752
753
754
755
756
757
...
792
793
794
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
795
796
797
0
@@ -178,12 +178,12 @@ unsigned char finalcount[8];
0
 #endif
0
 }
0
 
0
-static cairo_surface_t *
0
+cairo_surface_t *
0
 shoes_surface_create_from_pixels(PIXEL *pixels, int width, int height)
0
 {
0
   guchar *cairo_pixels;
0
   cairo_surface_t *surface;
0
- static const cairo_user_data_key_t key;
0
+ cairo_user_data_key_t key;
0
   int j;
0
  
0
   cairo_pixels = (guchar *)g_malloc(4 * width * height);
0
@@ -235,7 +235,7 @@ shoes_surface_create_from_pixels(PIXEL *pixels, int width, int height)
0
 cairo_surface_t *
0
 shoes_png_size(char *filename, int *width, int *height)
0
 {
0
- unsigned char *sig = SHOE_ALLOC_N(char, 32);
0
+ unsigned char *sig = SHOE_ALLOC_N(unsigned char, 32);
0
   cairo_surface_t *surface = NULL;
0
   FILE *image = fopen(filename, "rb");
0
   if (image == NULL) return NULL;
0
@@ -414,12 +414,12 @@ typedef struct shoes_jpeg_error_mgr *shoes_jpeg_err;
0
 
0
 #define JPEG_INPUT_BUF_SIZE 4096
0
 
0
-static void
0
+void
0
 shoes_jpeg_term_source(j_decompress_ptr cinfo)
0
 {
0
 }
0
 
0
-static void
0
+void
0
 shoes_jpeg_init_source(j_decompress_ptr cinfo)
0
 {
0
   shoes_jpeg_file src = (shoes_jpeg_file) cinfo->src;
0
@@ -427,7 +427,7 @@ shoes_jpeg_init_source(j_decompress_ptr cinfo)
0
 }
0
 
0
 
0
-static boolean
0
+boolean
0
 shoes_jpeg_fill_input_buffer(j_decompress_ptr cinfo)
0
 {
0
   shoes_jpeg_file src = (shoes_jpeg_file)cinfo->src;
0
@@ -451,7 +451,7 @@ shoes_jpeg_fill_input_buffer(j_decompress_ptr cinfo)
0
   return 1;
0
 }
0
 
0
-static void
0
+void
0
 shoes_jpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
0
 {
0
   shoes_jpeg_file src = (shoes_jpeg_file)cinfo->src;
0
@@ -468,7 +468,7 @@ shoes_jpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
0
   }
0
 }
0
 
0
-static void
0
+void
0
 jpeg_file_src(j_decompress_ptr cinfo, FILE *infile)
0
 {
0
   shoes_jpeg_file src;
0
@@ -496,7 +496,7 @@ jpeg_file_src(j_decompress_ptr cinfo, FILE *infile)
0
   src->pub.next_input_byte = NULL; /* until buffer loaded */
0
 }
0
  
0
-static void
0
+void
0
 shoes_jpeg_fatal(j_common_ptr cinfo)
0
 {
0
   shoes_jpeg_err jpgerr = (shoes_jpeg_err)cinfo->err;
0
@@ -596,13 +596,13 @@ done:
0
   return surface;
0
 }
0
 
0
-static char
0
+char
0
 shoes_has_ext(char *fname, int len, const char *ext)
0
 {
0
   return strncmp(fname + (len - strlen(ext)), ext, strlen(ext)) == 0;
0
 }
0
 
0
-static unsigned char
0
+unsigned char
0
 shoes_check_file_exists(VALUE path)
0
 {
0
   if (!RTEST(rb_funcall(rb_cFile, rb_intern("exists?"), 1, path)))
0
@@ -614,7 +614,7 @@ shoes_check_file_exists(VALUE path)
0
   return TRUE;
0
 }
0
 
0
-static void
0
+void
0
 shoes_unsupported_image(VALUE path)
0
 {
0
   VALUE ext = rb_funcall(rb_cFile, rb_intern("extname"), 1, path);
0
@@ -624,7 +624,7 @@ shoes_unsupported_image(VALUE path)
0
     RSTRING_PTR(path), RSTRING_PTR(ext));
0
 }
0
 
0
-static void
0
+void
0
 shoes_failed_image(VALUE path)
0
 {
0
   VALUE ext = rb_funcall(rb_cFile, rb_intern("extname"), 1, path);
0
@@ -634,7 +634,7 @@ shoes_failed_image(VALUE path)
0
     RSTRING_PTR(path), RSTRING_PTR(ext));
0
 }
0
 
0
-static cairo_surface_t *
0
+cairo_surface_t *
0
 shoes_surface_create_from_file(char *fname, char *dname, int *width, int *height)
0
 {
0
   int len = strlen(dname);
0
@@ -653,6 +653,24 @@ shoes_surface_create_from_file(char *fname, char *dname, int *width, int *height
0
   return img;
0
 }
0
 
0
+int
0
+shoes_cache_lookup(char *imgpath, shoes_cached_image **image)
0
+{
0
+ shoes_cache_entry *cached = NULL;
0
+ int ret = st_lookup(shoes_world->image_cache, (st_data_t)imgpath, (st_data_t *)&cached);
0
+ if (ret) *image = cached->image;
0
+ return ret;
0
+}
0
+
0
+void
0
+shoes_cache_insert(unsigned char type, VALUE imgpath, shoes_cached_image *image)
0
+{
0
+ shoes_cache_entry *cached = SHOE_ALLOC(shoes_cache_entry);
0
+ cached->type = type;
0
+ cached->image = image;
0
+ st_insert(shoes_world->image_cache, (st_data_t)strdup(RSTRING_PTR(imgpath)), (st_data_t)cached);
0
+}
0
+
0
 shoes_code
0
 shoes_load_imagesize(VALUE imgpath, int *width, int *height)
0
 {
0
@@ -718,7 +736,7 @@ shoes_download_image_handler(shoes_download_event *de, void *data)
0
   {
0
     int i, j, width, height;
0
     SHA1_CTX context;
0
- unsigned char *digest = SHOE_ALLOC_N(char, 20), *buffer = SHOE_ALLOC_N(char, 16384);
0
+ unsigned char *digest = SHOE_ALLOC_N(unsigned char, 20), *buffer = SHOE_ALLOC_N(unsigned char, 16384);
0
 
0
     if (idat->status == 304)
0
     {
0
@@ -733,6 +751,7 @@ shoes_download_image_handler(shoes_download_event *de, void *data)
0
       if (shoes_cache_lookup(idat->uripath, &cached) && cached->surface == shoes_world->blank_image)
0
       {
0
         shoes_image_download_event *side = SHOE_ALLOC(shoes_image_download_event);
0
+ SHOE_MEMZERO(side, shoes_image_download_event, 1);
0
         cached->surface = img;
0
         cached->width = width;
0
         cached->height = height;
0
@@ -773,24 +792,6 @@ shoes_download_image_handler(shoes_download_event *de, void *data)
0
   return SHOES_DOWNLOAD_CONTINUE;
0
 }
0
 
0
-int
0
-shoes_cache_lookup(char *imgpath, shoes_cached_image **image)
0
-{
0
- shoes_cache_entry *cached = NULL;
0
- int ret = st_lookup(shoes_world->image_cache, (st_data_t)imgpath, (st_data_t *)&cached);
0
- if (ret) *image = cached->image;
0
- return ret;
0
-}
0
-
0
-void
0
-shoes_cache_insert(unsigned char type, VALUE imgpath, shoes_cached_image *image)
0
-{
0
- shoes_cache_entry *cached = SHOE_ALLOC(shoes_cache_entry);
0
- cached->type = type;
0
- cached->image = image;
0
- st_insert(shoes_world->image_cache, (st_data_t)strdup(RSTRING_PTR(imgpath)), (st_data_t)cached);
0
-}
0
-
0
 shoes_cached_image *
0
 shoes_load_image(VALUE slot, VALUE imgpath)
0
 {
...
94
95
96
 
...
94
95
96
97
0
@@ -94,3 +94,4 @@ VALUE shoes_dialog_open(VALUE);
0
 VALUE shoes_dialog_save(VALUE);
0
 VALUE shoes_dialog_open_folder(VALUE);
0
 VALUE shoes_dialog_save_folder(VALUE);
0
+void shoes_native_move_file(char *, char *);
...
1095
1096
1097
 
 
 
 
 
 
...
1095
1096
1097
1098
1099
1100
1101
1102
1103
0
@@ -1095,3 +1095,9 @@ shoes_dialog_save_folder(VALUE self)
0
   return shoes_dialog_chooser(self, "Save folder...", GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER,
0
     GTK_STOCK_SAVE);
0
 }
0
+
0
+void
0
+shoes_native_move_file(char *src, char *dest)
0
+{
0
+ rename(src, dest);
0
+}
...
1546
1547
1548
 
 
 
 
 
 
...
1546
1547
1548
1549
1550
1551
1552
1553
1554
0
@@ -1546,3 +1546,9 @@ shoes_dialog_save_folder(VALUE self)
0
 {
0
   return shoes_dialog_chooser2(self, "Save folder...", BIF_RETURNONLYFSDIRS);
0
 }
0
+
0
+void
0
+shoes_native_move_file(char *src, char *dest)
0
+{
0
+ MoveFile(src, dest);
0
+}
...
3839
3840
3841
 
3842
3843
3844
...
3863
3864
3865
3866
3867
 
3868
3869
3870
...
3839
3840
3841
3842
3843
3844
3845
...
3864
3865
3866
 
 
3867
3868
3869
3870
0
@@ -3839,6 +3839,7 @@ shoes_response_status(VALUE self)
0
   return rb_iv_get(self, "status");
0
 }
0
 
0
+// TODO: handle exceptions
0
 int shoes_catch_message(unsigned int name, VALUE obj, void *data) {
0
   int ret = SHOES_DOWNLOAD_CONTINUE;
0
   switch (name) {
0
@@ -3863,8 +3864,7 @@ int shoes_catch_message(unsigned int name, VALUE obj, void *data) {
0
       if (side->status != 304)
0
       {
0
         realpath = rb_funcall(cShoes, rb_intern("image_cache_path"), 2, hash, uext);
0
- rb_funcall(rb_const_get(rb_cObject, rb_intern("FileUtils")),
0
- rb_intern("mv"), 2, path, realpath);
0
+ rename(side->filepath, RSTRING_PTR(realpath));
0
       }
0
 
0
       free(side->filepath);

Comments

    No one has commented yet.