Module: TT::System
- Defined in:
- TT_Lib2/system.rb,
cext/tt_lib2/tt_lib2/src/ruby/system/system.cpp
Overview
…
Constant Summary
- PLATFORM_IS_OSX =
(Object::RUBY_PLATFORM =~ /darwin/i) ? true : false
- PLATFORM_IS_WINDOWS =
!PLATFORM_IS_OSX
- TEMP_PATH =
File.( ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] ).freeze
Class Method Summary collapse
- .font_names(options) ⇒ Array<String>
- .get_virtual_file(filename) ⇒ String, Nil
- .is_osx? ⇒ Boolean
- .is_windows? ⇒ Boolean
-
.local_data_path ⇒ String, Nil
Returns path to the user's local data path.
- .platform_supported? ⇒ Boolean
- .platform_version ⇒ Array<Integer, Integer, Integer>
-
.temp_path ⇒ String
Returns path to the user's temp path.
Class Method Details
.font_names(options) ⇒ Array<String>
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'cext/tt_lib2/tt_lib2/src/ruby/system/system.cpp', line 27
VALUE wrap_font_names(int argc, VALUE* argv, VALUE self)
{
VALUE options = Qnil;
rb_scan_args(argc, argv, "01", &options);
if (NIL_P(options)) options = rb_hash_new();
Check_Type(options, T_HASH);
FontOptions font_options {
RTEST(GetHashValue(options, "device", Qfalse)),
RTEST(GetHashValue(options, "raster", Qfalse)),
RTEST(GetHashValue(options, "vector", Qtrue))
};
auto fonts = GetFontNames(font_options);
VALUE names = rb_ary_new_capa(static_cast<long>(fonts.size()));
for (const auto& font : fonts)
{
auto name = GetVALUE(font.c_str());
rb_ary_push(names, name);
}
return names;
}
|
.get_virtual_file(filename) ⇒ String, Nil
40 41 42 43 44 45 46 |
# File 'TT_Lib2/system.rb', line 40 def self.get_virtual_file( filename ) if TT::System.is_windows? TT::Win32.get_virtual_file( filename ) else nil end end |
.is_osx? ⇒ Boolean
26 27 28 |
# File 'TT_Lib2/system.rb', line 26 def self.is_osx? PLATFORM_IS_OSX end |
.is_windows? ⇒ Boolean
32 33 34 |
# File 'TT_Lib2/system.rb', line 32 def self.is_windows? PLATFORM_IS_WINDOWS end |
.local_data_path ⇒ String, Nil
Returns path to the user's local data path.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'TT_Lib2/system.rb', line 79 def self.local_data_path if PLATFORM_IS_WINDOWS path = ENV['LOCALAPPDATA'] # Ruby 1.8 cannot handle paths with non-ASCII characters. If the ENV # variable returns a path that Ruby cannot find, try to find it using # the Win32 API. if path.nil? || !File.exist?( path ) path = TT::Win32.get_short_folder_path_ansi( TT::Win32::CSIDL_LOCAL_APPDATA ) end else # http://sketchucation.com/forums/viewtopic.php?f=180&t=52730&p=482216#p482211 # # Sketchup.find_support_file('Plugins') might not be reliable. So look for # 'OldColors' folder instead. This should give a path in the User folder # on SketchUp 8 and older as well as SketchUp 13. # # Because we don't know what future SketchUp versions does we look for # 'Plugins' last, as since SketchUp 2013 the folder should be in the user # folder. paths = ['OldColors', 'Plugins'] sketchup_path = paths.find { |path| Sketchup.find_support_file( path ) } path = File.join( sketchup_path, '..', '..' ) File.( path ) end path end |
.platform_supported? ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 70 |
# File 'TT_Lib2/system.rb', line 60 def self.platform_supported? if TT::System.is_osx? min_major, min_minor = [10, 7] version = self.platform_version return true if version.x > min_major return true if version.x == min_major && version.y >= min_minor false else true end end |
.platform_version ⇒ Array<Integer, Integer, Integer>
50 51 52 53 54 55 56 |
# File 'TT_Lib2/system.rb', line 50 def self.platform_version if PLATFORM_IS_OSX %x(sw_vers -productVersion).chop.split('.').map { |x| x.to_i } else raise NotImplementedError end end |
.temp_path ⇒ String
Returns path to the user's temp path.
113 114 115 |
# File 'TT_Lib2/system.rb', line 113 def self.temp_path TEMP_PATH.dup end |