def NativeFileType.best_fit(file_system_image,filename,contents,file_type=nil,aux_code=nil)
candidates={}
NativeFileType.all_native_file_types.each do |native_file_type|
if !native_file_type.file_system_file_types.keys.include?(file_system_image.file_system) then
RipXploreLog.debug("skipping #{native_file_type} - can't reside on #{file_system_image.file_system}")
else
RipXploreLog.debug("checking native file type #{native_file_type}")
candidate_score=native_file_type.compatability_score(file_system_image,filename,contents,file_type,aux_code)
RipXploreLog.debug("score - #{candidate_score}")
candidates[native_file_type]=candidate_score
end
end
if candidates.length==0 then
RipXploreLog.debug( 'no valid combination of file system and native file types found')
return nil
end
best_candidate=candidates.keys.sort{|a,b| candidates[b]<=>candidates[a]}[0]
RipXploreLog.debug("best candidate for #{filename} = #{best_candidate} score: #{candidates[best_candidate]}")
native_file=best_candidate.new(file_system_image,filename,contents,file_type,aux_code)
if GenericGIF.is_gif?(native_file) then
RipXploreLog.debug(" #{filename} is a GIF")
native_file.extend GenericGIF
end
native_file
end