public
Description: a tiny graphical app kit for ruby
Homepage: http://code.whytheluckystiff.net/shoes
Clone URL: git://github.com/why/shoes.git
 * lib/shoes/pack.rb: working on injecting the full installers inside the exes 
 and dmgs.  a flimsy first try.
 * req/binject: need to get a progress meter out of the injection.
 * shoes/ruby.c: don't hide or show uncreated gtk elements.
why (author)
Sun Jun 22 13:57:25 -0700 2008
commit  d1ac0ded79318256c726c1ddd57127e70cf1d171
tree    4ed72fb30a4c3eb13488959923eafd0cfdbf8bbf
parent  5b0a6e8aab39a9d33c738c3c86331942201f28a1
...
7
8
9
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
12
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
 
19
20
21
...
105
106
107
 
 
 
 
 
108
109
110
...
114
115
116
117
 
118
119
120
121
122
123
 
124
125
126
...
148
149
150
151
 
152
153
154
...
160
161
162
163
164
 
 
165
166
167
...
171
172
173
174
175
176
177
178
179
 
 
 
 
 
 
 
 
 
180
181
182
...
7
8
9
 
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
47
48
49
50
...
134
135
136
137
138
139
140
141
142
143
144
...
148
149
150
 
151
152
153
154
155
156
 
157
158
159
160
...
182
183
184
 
185
186
187
188
...
194
195
196
 
 
197
198
199
200
201
...
205
206
207
 
208
209
 
 
 
210
211
212
213
214
215
216
217
218
219
220
221
0
@@ -7,15 +7,44 @@ require 'binject'
0
 
0
 class Shoes
0
   module Pack
0
-    def self.exe(script)
0
+    def self.pkg(platform, opt)
0
+      url = 
0
+        case opt
0
+        when I_YES; "http://hacketyhack.net/pkg/#{platform}/shoes"
0
+        when I_NOV; "http://hacketyhack.net/pkg/#{platform}/shoes-novideo"
0
+        end
0
+      if url
0
+        url = "http://hacketyhack.net" + open(url).read.strip
0
+        open(url)
0
+      end
0
+    end
0
+
0
+    def self.exe(script, opt, progress = nil)
0
+      size = File.size(script)
0
       f = File.open(script)
0
       exe = Binject::EXE.new(File.join(DIR, "static", "stubs", "blank.exe"))
0
       exe.inject("SHOES_FILENAME", File.basename(script))
0
       exe.inject("SHOES_PAYLOAD", f)
0
-      exe.save(script.gsub(/\.\w+$/, '') + ".exe")
0
+      f2 = pkg("win32", opt)
0
+      if f2
0
+        f3 = File.open(f2.path, 'rb')
0
+        exe.inject("SHOES_SETUP", f3)
0
+      end
0
+
0
+      count = 0
0
+      exe.save(script.gsub(/\.\w+$/, '') + ".exe") do |len|
0
+        count += len
0
+        progress.fraction = 0.3
0
+      end
0
+
0
+      f.close
0
+      if f2
0
+        f2.close
0
+        f3.close
0
+      end
0
     end
0
 
0
-    def self.dmg(script, progress = nil)
0
+    def self.dmg(script, opt, progress = nil)
0
       name = File.basename(script).gsub(/\.\w+$/, '')
0
       app_name = name.capitalize.gsub(/[-_](\w)/) { $1.capitalize }
0
       vol_name = name.capitalize.gsub(/[-_](\w)/) { " " + $1.capitalize }
0
@@ -105,6 +134,11 @@ END
0
         File.join(mac_dir, "cocoa-install"))
0
 
0
       dmg = Binject::DMG.new(File.join(tmp_dir, "blank.hfz"), vol_name)
0
+      f2 = pkg("osx", opt)
0
+      if f2
0
+        dmg.grow(10)
0
+        dmg.inject_file("setup.dmg", f2.path)
0
+      end
0
       dmg.inject_dir(app_app, app_dir)
0
       dmg.chmod_file(0755, "#{app_app}/Contents/MacOS/#{name}-launch")
0
       dmg.chmod_file(0755, "#{app_app}/Contents/MacOS/cocoa-install")
0
@@ -114,13 +148,13 @@ END
0
       FileUtils.rm_rf(tmp_dir) if File.exists? tmp_dir
0
     end
0
 
0
-    def self.linux(script)
0
+    def self.linux(script, opt, progress = nil)
0
     end
0
   end
0
 
0
   I_NET = "No, download Shoes if it's absent."
0
   I_YES = "Yes, I want Shoes included."
0
-  I_VID = "Yes, include Shoes with video support."
0
+  I_NOV = "Yes, include Shoes, but without video support."
0
   PackMake = proc do
0
     background "#EEE"
0
 
0
@@ -148,7 +182,7 @@ END
0
           end
0
 
0
           para "Include Shoes with your app? "
0
-          @inc = list_box :items => [I_NET, I_YES, I_VID], :width => 0.6 do
0
+          @inc = list_box :items => [I_NET, I_YES, I_NOV], :width => 0.6 do
0
             est_recount
0
           end
0
         end
0
@@ -160,8 +194,8 @@ END
0
           base = 
0
             case @inc.text
0
             when I_NET; 70
0
-            when I_YES; 2500
0
-            when I_VID; 7000
0
+            when I_YES; 7000
0
+            when I_NOV; 2500
0
             end
0
           base += File.size(@path.text) / 1024
0
           @est.replace "Estimated size of each app: ", strong(base > 1024 ?
0
@@ -171,12 +205,17 @@ END
0
         flow :margin_top => 10, :margin_left => 310 do
0
           button "OK", :margin_right => 4 do
0
             @page1.hide
0
-            @prog.fraction = 0
0
             @page2.show 
0
             @path2.replace File.basename(@path.text)
0
-            Shoes::Pack.exe(@path.text)
0
-            Shoes::Pack.dmg(@path.text, @prog)
0
-            Shoes::Pack.linux(@path.text)
0
+            Thread.start(@prog) do |prog|
0
+              begin
0
+                Shoes::Pack.exe(@path.text, @inc.text, prog)
0
+                Shoes::Pack.dmg(@path.text, @inc.text, prog)
0
+                Shoes::Pack.linux(@path.text, @inc.text, prog)
0
+              rescue => e
0
+                Kernel.p [e.class, e.message]
0
+              end
0
+            end
0
           end
0
           button "Cancel" do
0
             close
...
61
62
63
64
 
65
66
67
...
87
88
89
 
90
91
92
...
272
273
274
275
 
276
277
278
279
 
 
280
281
282
283
284
 
285
286
287
...
292
293
294
 
 
295
296
297
...
402
403
404
405
 
406
407
408
409
410
411
412
 
413
414
415
416
417
418
 
419
420
421
...
438
439
440
441
 
442
443
444
...
514
515
516
 
517
518
519
...
61
62
63
 
64
65
66
67
...
87
88
89
90
91
92
93
...
273
274
275
 
276
277
278
279
280
281
282
283
284
285
286
 
287
288
289
290
...
295
296
297
298
299
300
301
302
...
407
408
409
 
410
411
412
413
414
415
416
 
417
418
419
420
421
422
 
423
424
425
426
...
443
444
445
 
446
447
448
449
...
519
520
521
522
523
524
525
0
@@ -61,7 +61,7 @@ typedef struct {
0
   int ids, resids;
0
   unsigned int namestart, datastart, datapos, dataend, vdelta;
0
   char signature[4];
0
-  VALUE adds;
0
+  VALUE adds, proc;
0
   FILE *file, *out;
0
 } binject_exe_t;
0
 
0
@@ -87,6 +87,7 @@ binject_exe_alloc(VALUE klass)
0
   binject_exe_t *binj = ALLOC(binject_exe_t);
0
   MEMZERO(binj, binject_exe_t, 1);
0
   binj->adds = rb_ary_new();
0
+  binj->proc = Qnil;
0
   return Data_Wrap_Struct(klass, binject_exe_mark, binject_exe_free, binj);
0
 }
0
 
0
@@ -272,16 +273,18 @@ binject_exe_data_len(binject_exe_t *binj)
0
 }
0
 
0
 void
0
-binject_exe_string_copy(binject_exe_t *binj, char *str, unsigned int size, unsigned int pos)
0
+binject_exe_string_copy(binject_exe_t *binj, char *str, unsigned int size, unsigned int pos, VALUE proc)
0
 {
0
   int mark = ftell(binj->out);
0
   fseek(binj->out, pos, SEEK_SET);
0
   fwrite(str, sizeof(char), size, binj->out);
0
+  if (!NIL_P(proc))
0
+    rb_funcall(proc, rb_intern("call"), 1, INT2NUM(size));
0
   fseek(binj->out, mark, SEEK_SET);
0
 }
0
 
0
 void
0
-binject_exe_file_copy(FILE *file, FILE *out, unsigned int size, unsigned int pos1, unsigned int pos2)
0
+binject_exe_file_copy(FILE *file, FILE *out, unsigned int size, unsigned int pos1, unsigned int pos2, VALUE proc)
0
 {
0
   char buf[BUFSIZE];
0
   int mark1 = ftell(file), mark2 = ftell(out);
0
@@ -292,6 +295,8 @@ binject_exe_file_copy(FILE *file, FILE *out, unsigned int size, unsigned int pos
0
     unsigned int len = size > BUFSIZE ? BUFSIZE : size;
0
     fread(buf, sizeof(char), len, file);
0
     fwrite(buf, sizeof(char), len, out);
0
+    if (!NIL_P(proc))
0
+      rb_funcall(proc, rb_intern("call"), 1, INT2NUM(len));
0
     size -= len;
0
   }
0
   fseek(file, mark1, SEEK_SET);
0
@@ -402,20 +407,20 @@ binject_exe_rewrite(binject_exe_t *binj, char *buf, char *out, int offset, int o
0
             if (ctype == rb_cString)
0
             {
0
               rdat->Size = RSTRING_LEN(obj);
0
-              binject_exe_string_copy(binj, RSTRING_PTR(obj), RSTRING_LEN(obj), binj->datapos);
0
+              binject_exe_string_copy(binj, RSTRING_PTR(obj), RSTRING_LEN(obj), binj->datapos, binj->proc);
0
             }
0
             else
0
             {
0
               OpenFile *fptr;
0
               rdat->Size = binject_exe_file_size(obj);
0
               GetOpenFile(obj, fptr);
0
-              binject_exe_file_copy(GetReadFile(fptr), binj->out, rdat->Size, 0, binj->datapos);
0
+              binject_exe_file_copy(GetReadFile(fptr), binj->out, rdat->Size, 0, binj->datapos, binj->proc);
0
             }
0
             binj->datapos += rdat->Size;
0
             padlen = BINJ_PAD(rdat->Size, 4) - rdat->Size;
0
             if (padlen > 0)
0
             {
0
-              binject_exe_string_copy(binj, pe_pad, padlen, binj->datapos);
0
+              binject_exe_string_copy(binj, pe_pad, padlen, binj->datapos, binj->proc);
0
               binj->datapos += padlen;
0
             }
0
             oc++;
0
@@ -438,7 +443,7 @@ binject_exe_rewrite(binject_exe_t *binj, char *buf, char *out, int offset, int o
0
       // printf("RESDATA: %x TO %x AT %x / %x\n", rde->OffsetToData, rde2->OffsetToData, 
0
       //   binj->namestart, binj->datastart);
0
       binject_exe_file_copy(binj->file, binj->out, rdat->Size, 
0
-        rdat->OffsetToData - binj->vdelta, binj->datapos);
0
+        rdat->OffsetToData - binj->vdelta, binj->datapos, binj->proc);
0
       // printf("DATA: %x TO %x\n", rdat->OffsetToData, binj->datapos);
0
       binj->datapos += rdat->Size;
0
       binj->dataend = (rdat->OffsetToData - binj->vdelta) + rdat->Size;
0
@@ -514,6 +519,7 @@ binject_exe_save(VALUE self, VALUE file)
0
   binj->namestart = 0;
0
   binj->datastart = 0;
0
   binj->datapos = 0;
0
+  binj->proc = rb_block_proc();
0
   fseek(binj->file, 0, SEEK_SET);
0
 
0
   pos = 0;
...
2790
2791
2792
2793
 
2794
2795
2796
...
2799
2800
2801
2802
 
2803
2804
2805
...
2790
2791
2792
 
2793
2794
2795
2796
...
2799
2800
2801
 
2802
2803
2804
2805
0
@@ -2790,7 +2790,7 @@ shoes_control_hide(VALUE self)
0
 {
0
   GET_STRUCT(control, self_t);
0
   ATTRSET(self_t->attr, hidden, Qtrue);
0
-  shoes_control_hide_ref(self_t->ref);
0
+  if (self_t->ref != NULL) shoes_control_hide_ref(self_t->ref);
0
   return self;
0
 }
0
 
0
@@ -2799,7 +2799,7 @@ shoes_control_show(VALUE self)
0
 {
0
   GET_STRUCT(control, self_t);
0
   ATTRSET(self_t->attr, hidden, Qfalse);
0
-  shoes_control_show_ref(self_t->ref);
0
+  if (self_t->ref != NULL) shoes_control_show_ref(self_t->ref);
0
   return self;
0
 }
0
 

Comments