Skip to content

Instantly share code, notes, and snippets.

@DanRathbun
Last active January 13, 2020 18:35
Show Gist options
  • Save DanRathbun/88a61c7c08a83cc4ca2f3144fe7116eb to your computer and use it in GitHub Desktop.
Save DanRathbun/88a61c7c08a83cc4ca2f3144fe7116eb to your computer and use it in GitHub Desktop.
SketchUp Embedded Ruby System::Paths module
# encoding: UTF-8
#
# Boilerplate Ideas for SketchUp Embedded Ruby System::Paths module.
require 'SketchUp_Ruby_System'
module System
if (Sketchup.platform == :platform_win rescue RUBY_PLATFORM !~ /darwin/)
# System::Paths for MS Windows
#
# INDEX for common "Windowsy" variables
# ------------ ---------------------------
# AppData : user_application_data()
# gem_home : user_gem_home()
# gem_path : user_gem_path()
# LocalAppData : user_application_data_local()
# ProgramData : shared_application_data()
# Public : shared_home()
# Temp : temporary_files()
# UserProfile : user_home()
#
module Paths # for MS Windows
extend self # can be used as library or a mixin module
# The shared application data space where non-user specific data is stored.
# The application subfolder is often within a unique vendor named subfolder.
# This location may require admin write privileges.
def shared_application_data
System.get_env('ProgramData')
end
# The public shared user document space accessible by any user acccount.
# No guarantee of subfolders existing. Check existance and create
# sudirectories as needed. (Default subfolders vary by platform.)
def shared_home
System.get_env('Public')
end
# The path to SketchUp's SSL certificate file.
def ssl_certificate
System.get_env('SSL_CERT_FILE')
end
# The path to the temporary files directory. Applications should always
# cleanup their own temporary files and not rely upon automatic cleanup
# utilities. This location must not be used for persistent files or logs.
# Be aware that this location can be changed to outside the user data path.
# So always check read and write accessibility. If necessary, an extension
# can create it's own temporary files folder beneath it's own folder and
# always know it has read, write and delete privileges there.
def temporary_files
System.get_env('Temp')
end
alias_method :temp, :temporary_files
# The user specific data space used by applications. On Windows this path's
# data and documents can also be synchronized by a roaming profile server.
# Applications store user specific data in a subfolder named for themselves.
# The application subfolder is often within a unique vendor named subfolder.
def user_application_data
System.get_env('AppData')
end
# The application data space for user specific data unique to a workstation.
# On Windows this is for application data unique to a workstation that will
# not be synchronized by a profile server or copied to other workstations.
# On MacOS there does not appear to be any difference between roaming and
# local user profiles, so this is just an alias for user_application_data().
def user_application_data_local
System.get_env('LocalAppData')
end
# The user's Rubygems home path where the SketchUp version installs gems for
# the current user's use.
def user_gem_home
System.get_env('GEM_HOME')
end
alias_method :user_gem_path, :user_gem_home
# The user's home directory path.
def user_home
System.get_env('UserProfile')
end
end # Paths for MS Windows
else
module Paths # for MacOS
extend self # can be used as library or a mixin module
# The shared application data space where non-user specific data is stored.
# The application subfolder is often within a unique vendor named subfolder.
# This location may require admin write privileges.
def shared_application_data
File.expand_path('/Library/Application Support')
end
# The public shared user document space accessible by any user acccount.
# No guarantee of subfolders existing. Check existance and create
# subdirectories as needed. (Default subfolders vary by platform.)
def shared_home
'/Users/Shared'
end
# The path to SketchUp's SSL certificate file.
def ssl_certificate
ENV['SSL_CERT_FILE']
end
# The path to the temporary files directory. Applications should always
# cleanup their own temporary files and not rely upon automatic cleanup
# utilities. This location must not be used for persistent files or logs.
# Be aware that this location can be changed to outside the user data path.
# So always check read and write accessibility. If necessary, an extension
# can create it's own temporary files folder beneath it's own folder and
# always know it has read, write and delete privileges there.
def temporary_files
ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP']
end
alias_method :temp, :temporary_files
# The user specific data space used by applications. On Windows this is
# for remote (roaming) data and documents synchronized by a profile server.
# Applications store user specific data in a subfolder named for themselves.
# The application subfolder is often within a unique vendor named subfolder.
def user_application_data
File.expand_path('~/Library/Application Support')
end
# The application data space for user specific data unique to a workstation.
# On Windows this is for application data unique to a workstation that will
# not be synchronized by a profile server or copied to other workstations.
# On MacOS there does not appear to be any difference between roaming and
# local user profiles, so this is just an alias for user_application_data().
def user_application_data_local
File.expand_path('~/Library/Application Support')
end
# The user's Rubygems home path where the SketchUp version installs gems for
# the current user's use.
def user_gem_home
ENV['GEM_HOME']
end
alias_method :user_gem_path, :user_gem_home
# The user's home directory path.
def user_home
ENV['HOME']
end
end # Paths for MacOS
end # platform conditional definitions
end # System
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment