-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdragonruby-update
executable file
·59 lines (48 loc) · 2.67 KB
/
dragonruby-update
1
2
3
4
5
6
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
51
52
53
54
55
56
57
58
59
#!/usr/bin/env ruby
require "zip"
# given a path to a dragonruby .zip file, this will extract it overtop of your folder BUT preserve `mygame`.
zip_file = ARGV[0]
# no argument? use ours
project_path = ARGV[1] || File.expand_path(".")
if ARGV.length == 0
puts("run me with ./dragonruby-update path-to-zip-file-you-downloaded.zip [folder]")
end
# TODO: the top of the zip folder will be the name and a platform, need to strip out.
# #!/bin/sh
# OSTYPE=`uname -s`
# if [ "x$OSTYPE" = "xDarwin" ]; then
# PLATFORM=macos
# DLLEXT=dylib
# else
# PLATFORM=linux-amd64
# DLLEXT=so
# fi
PLATFORM = "macos"
puts <<~HEREDOC
we got:
zip file: #{zip_file}
project path: #{project_path}
HEREDOC
# luke@Lisas-Air dragonruby-template % ./dragonruby-update ~/Downloads/dragonruby-pro-macos.zip ~/project/war_pigs
# we got:
# zip file: /Users/luke/Downloads/dragonruby-pro-macos.zip
# project path: /Users/luke/project/war_pigs
# exclude mygame, move everything else?
# rsync -ax --exclude [relative path to directory to exclude] /path/from /path/to
# glob all files in folder
# for anything NOT in the list that was extracted, show you them and say "hey, delete?"
# and then yes/no to delete
Zip::File.open(zip_file) do |zipfile|
# TODO: this has an issue where your updates will accrete over each other - files that weren't in the zip
# of the new version won't be removed.
# is it worth fixing?
zipfile.each do |f|
# ./dragonruby-update:30:in `block (2 levels) in <main>': undefined method `include?' for #<Zip::Entry:0x0000000108b85b60 @local_header_offset=0, @local_header_size=nil, @internal_file_attributes=0, @external_file_attributes=1106051088, @header_signature=33639248, @version_needed_to_extract=10, @version=30, @ftype=:directory, @filepath=nil, @gp_flags=0, @follow_symlinks=false, @restore_times=false, @restore_permissions=false, @restore_ownership=false, @unix_uid=nil, @unix_gid=nil, @unix_perms=493, @dirty=false, @fstype=3, @zipfile="/Users/luke/Downloads/dragonruby-pro-macos.zip", @name="dragonruby-macos/", @comment="", @extra={"UniversalTime"=>#<Zip::ExtraField::UniversalTime:0x0000000108b84c60 @ctime=nil, @mtime=2023-10-16 04:05:22 -0600, @atime=nil, @flag=3>, "Unknown"=>"ux\\v\\x00\\x01\\x04\\xF5\\x01\\x00\\x00\\x04\\x14\\x00\\x00\\x00"}, @compressed_size=0, @crc=0, @compression_method=0, @size=0, @time=2023-10-16 05:05:22 -0600, @last_mod_time=10411, @last_mod_date=22352, @name_length=17, @extra_length=24, @comment_length=0> (NoMethodError)
next if f.name.include?("mygame")
destination_path = File.join(project_path, f.name.delete_prefix("dragonruby-#{PLATFORM}"))
zipfile.extract(f, destination_path) { |entry, path|
puts("updated #{path}")
true
}
end
end