git-svn-id: http://svn.code.sf.net/p/netboot65/code@137 93682198-c243-4bdb-bd91-e943c89aac3b

This commit is contained in:
jonnosan 2009-05-15 12:23:01 +00:00
parent 1f536b8c7c
commit 139c0769de
3 changed files with 73 additions and 0 deletions

3
CHANGES.txt Normal file
View File

@ -0,0 +1,3 @@
0.9.7
- tweak directory listing code in server so $ works by itself
- client & server updated to support subdirectories (prefixed by $)

1
dist/make_dist.rb vendored
View File

@ -25,6 +25,7 @@ end
["client/nb65/nb65_std_cart.bin","c64/"],
["client/nb65/d64_upload.prg","boot/"],
["server/lib/tftp_server.rb","lib"],
["server/lib/file_list.rb","lib"],
["server/bin/tftp_only_server.rb","bin/tftp_server.rb"],
#["server/bin/import_ags_games.rb","bin"],
#["server/boot/BOOTA2.PG2","boot"],

69
server/lib/file_list.rb Normal file
View File

@ -0,0 +1,69 @@
class FileList
FILE_EXTENSIONS=[".prg",".pg2"]
def initialize(dir)
log_msg("building file list for #{dir}")
@file_list={}
@base_dir=dir
read_dir(dir,dir)
# puts @file_list.keys.sort.join("\n")
end
def [](path_mask)
path_mask.gsub!("//","/")
full_filename="#{@base_dir}/#{path_mask}"
puts full_filename
if (path_mask=~/^\$\/?(.*)\*(\..{1,3}$)/)
target_extension=$2.downcase
dirname="/#{$1}".sub(/\/$/,'') # trim any trailing /
current_dir=@file_list[dirname]
raise "invalid directory #{dirname}" if current_dir.nil?
s=""
s<<"$/\000" unless dirname==""
slash_index=0
while !(slash_index.nil?)
slash_index=dirname.index("/",slash_index+1)
break if slash_index.nil?
subdir=dirname[0,slash_index]
normalised_subdir="$/#{subdir}".gsub("//","/").gsub("//","/")
s<<"#{normalised_subdir}\000"
end
current_dir[:directories].each do |directory_attributes|
subdir=directory_attributes[0]
normalised_subdir="$/#{subdir}".gsub("//","/").gsub("//","/")
s<<"#{normalised_subdir}\000"
end
current_dir[:files].each do |filename|
s<<"#{filename}\000" if filename.downcase=~/#{target_extension}$/
end
s<<0.chr if s.length==0 #make sure there is at least one 'empty' string
s<<0.chr
return s
elsif (FileTest.file?(full_filename))
return File.open(full_filename,"rb").read
else
raise "invalid path mask #{full_filename}"
end
end
private
def read_dir(dir,base_dir)
dir_contents={:files=>[],:directories=>[]}
Dir.glob("#{dir}/**").each do |filename|
relative_filename=filename.sub(/#{base_dir}/,'')
if File.ftype(filename)=="directory"
dir_contents[:directories]<<[relative_filename,read_dir(filename,base_dir)]
elsif (relative_filename=~/(\..{1,3})$/)
ext=$1.downcase
dir_contents[:files]<<relative_filename if FILE_EXTENSIONS.include?(ext)
else puts "skipping #{relative_filename}"
end
end
@file_list[dir.sub(/#{base_dir}/,'')]=dir_contents
end
end