#-- # The MIT License # # Copyright (c) 2012-2014 Andrei Nesterov # # 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. #++ require 'xcodeproject/file_node' require 'xcodeproject/exceptions' module XcodeProject class PBXFileReference < FileNode def initialize(root, uuid, data) super(root, uuid, data) end def remove! root.build_files(uuid).each(&:remove!) parent.remove_child_uuid(uuid) root.remove_object(uuid) end def self.add(root, path) uuid, data = root.add_object(create_object_hash(path)) new(root, uuid, data) end private_class_method def self.create_object_hash(path) path = path.to_s name = File.basename(path) ext = File.extname(path) raise ParseError, "No such file type '#{name}'." unless FileTypeMap.include?(ext) data = [] data << %w[isa PBXFileReference] data << ['sourceTree', ''] # data << ['fileEncoding', '4'] # utf-8 data << ['lastKnownFileType', FileTypeMap[ext]] data << ['path', path] data << ['name', name] if name != path Hash[data] end FileTypeMap = { '.h' => 'sourcecode.c.h', '.c' => 'sourcecode.c.c', '.m' => 'sourcecode.c.objc', '.mm' => 'sourcecode.cpp.objcpp', '.hpp' => 'sourcecode.cpp.h', '.cpp' => 'sourcecode.cpp.cpp', '.cc' => 'sourcecode.cpp.cpp', '.swift' => 'sourcecode.swift', '.mp3' => 'audio.mp3', '.png' => 'image.png', '.jpeg' => 'image.jpeg', '.jpg' => 'image.jpeg', '.fnt' => 'text', '.txt' => 'text' }.freeze end end