$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) $:.unshift(File.dirname(__FILE__+"\\..")) unless $:.include?(File.dirname(__FILE__+"\\..")) || $:.include?(File.expand_path(File.dirname(__FILE__+"\\.."))) require 'FileSystem' # # class CbmDos file_system_image.end_track do directory_sector=file_system_image.get_sector(dir_track_no,dir_sector_no) dir_track_no=directory_sector[0] dir_sector_no=directory_sector[1] 0.upto(7) do |entry_number| directory_entry=directory_sector[DIRECTORY_ENTRY_SIZE*entry_number,DIRECTORY_ENTRY_SIZE] file_name=C64.s_to_ascii(directory_entry[0x05..0x14]).strip next if directory_entry[0x02]==0x00 #skip SCRATCHed files file_type=FILE_TYPES[directory_entry[0x02]%8] geos_file_type=GEOS_FILE_TYPES[directory_entry[0x18]] is_geos_file=(geos_file_type!=:not_geos) is_vlir=is_geos_file && (directory_entry[0x17]==0x01) # puts "geos file type: #{geos_file_type} #{is_geos_file} #{is_vlir}" file_track_no=directory_entry[0x03] file_sector_no=directory_entry[0x04] if (is_geos_file) then file_name=(directory_entry[0x05..0x14]).gsub(/\xa0/," ").strip #GEOS filenames will be ASCII not PETSCII info_block=file_system_image.get_sector(directory_entry[0x15],directory_entry[0x16]) file_contents=[info_block] end if (is_vlir) then # puts file_name record_block=file_system_image.get_sector(file_track_no,file_sector_no) 127.times do |i| record_no=i+1 record_track_no=record_block[2*record_no] record_sector_no=record_block[1+(2*record_no)] record_contents=nil until record_track_no==0 || record_track_no>file_system_image.end_track do record_contents="" if record_contents.nil? record_sector=file_system_image.get_sector(record_track_no,record_sector_no) break if record_sector.nil? record_track_no=record_sector[0] record_sector_no=record_sector[1] end_of_data= (record_track_no==0) ? record_sector[1] : 255 record_contents< file_system_image.end_track do file_sector=file_system_image.get_sector(file_track_no,file_sector_no) break if file_sector.nil? file_track_no=file_sector[0] file_sector_no=file_sector[1] end_of_data= (file_track_no==0) ? file_sector[1] : 255 file_contents+=file_sector[2..end_of_data] # puts "#{file_name} #{file_track_no} #{file_sector_no} #{end_of_data}" end end file=NativeFileType.best_fit(file_system_image,file_name,file_contents,file_type,geos_file_type) file.meta_data["c64_file_type"]="$%02x" % directory_entry[0x02] file.meta_data["first_block"]="track $%02x sector $%02x" % [directory_entry[0x03],directory_entry[04]] if (is_geos_file) then file.meta_data["geos_file_header"]="track $%02x sector $%02x" % [directory_entry[0x15],directory_entry[16]] file.meta_data["geos_file_structure_type"]="$%02x" % directory_entry[0x17] file.meta_data["geos_file_type"]="$%02x" % directory_entry[0x18] file.meta_data["geos_file_modified_date"]="%04d-%02d-%02d %02d:%02d" % [1900+directory_entry[0x19],directory_entry[0x1A],directory_entry[0x1B],directory_entry[0x1C],directory_entry[0x1D]] end files<0) then next_directory_sector_no = (candidate_sectors.include?(directory_sector_no+3) ? directory_sector_no+3 : candidate_sectors[0]) directory[00]=18 directory[01]=next_directory_sector_no file_system_image.set_sector(directory_track_no,directory_sector_no,directory) file_system_image.set_sector(directory_track_no,next_directory_sector_no,(0.chr)*256) #reset the directory sector we just added mark_sector_as_used(file_system_image,directory_track_no,next_directory_sector_no) return [directory_track_no,next_directory_sector_no,0] end directory_sector_no=next_directory_sector_no directory_track_no=next_directory_track_no end nil end def self.delete_file(file_system_image,filename) directory_filename=directory_entry_for_filename(filename) #first find this file's directory entry directory_track_no=18 directory_sector_no=1 while (directory_track_no !=0) do directory=file_system_image.get_sector(directory_track_no,directory_sector_no) raise "attempted to read invalid directory sector at T #{directory_track_no} S#{directory_sector_no}" if directory.nil? 8.times do |slot_no| slot_start=slot_no*0x20 next if directory[slot_start+2]==0 #skip files that are already deleted if directory[slot_start+5,16]==directory_filename then #found our file! # puts "found #{filename} at T #{directory_track_no} S #{directory_sector_no} slot #{slot_no}" #clear the directory entry directory[slot_start+2]=0 file_system_image.set_sector(directory_track_no,directory_sector_no,directory) #now mark the file sectors as being free in the BAM file_track_no=directory[slot_start+3] file_sector_no=directory[slot_start+4] until (file_track_no==0) do # puts "freeing T #{file_track_no} S #{file_sector_no}" mark_sector_as_free(file_system_image,file_track_no,file_sector_no) file_sector=file_system_image.get_sector(file_track_no,file_sector_no) file_track_no=file_sector[0] file_sector_no=file_sector[1] end return end end directory_track_no=directory[00] directory_sector_no=directory[01] end end end # == Author # Jonno Downes (jonno@jamtronix.com) # # == Copyright # Copyright (c) 2008,2009 Jonno Downes (jonno@jamtronix.com) # #Permission is hereby granted, free of charge, to any person obtaining #a copy of this software and associated documentation files (the #"Software"), to deal in the Software without restriction, including #without limitation the rights to use, copy, modify, merge, publish, #distribute, sublicense, and/or sell copies of the Software, and to #permit persons to whom the Software is furnished to do so, subject to #the following conditions: # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.