require 'sketchup.rb'
require 'extensions.rb'

module DM
  module Artisan

    VERSION = "1.2.7".freeze
    PLUGIN_NAME = "Artisan".freeze
    PLUGIN = self

    if Sketchup.version.to_i >= 16
      plugins = Sketchup.find_support_file("Plugins")
      if FileTest.exist?(File.join(plugins, "artisan_loader.rb"))
        UI.messagebox("You have an old version of Artisan installed.  Please delete the file" +
                      " 'artisan_loader.rb' and the folder 'artisan' from your SketchUp "+
                      "plugins folder in order for the newer version to function correctly.")
        UI.openURL("file://"+plugins)
      end

      path = File.dirname(__FILE__)
      path.force_encoding('UTF-8') if path.respond_to?(:force_encoding)
      loader = File.join(path, "DM_artisan/artisan_load")

      artisanExtension = SketchupExtension.new(PLUGIN_NAME, loader)
      artisanExtension.description=("Adds Tools->Artisan to the SketchUp interface.  The "+
          "Artisan submenu contains several tools for creating and editing organic geometry.")
      artisanExtension.version = "#{VERSION}"
      artisanExtension.creator = "Dale Martens (Whaat)"
      artisanExtension.copyright = "2016, Dale Martens. All rights reserved."
      Sketchup.register_extension artisanExtension, true
    else
      message = "SketchUp 2016 or newer is required to use this version of #{PLUGIN_NAME}. "\
        "Please disable the extension or remove it from your plugins folder."
      UI.messagebox(message)
    end
  end
end