Class: ShellInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/piggy-core/winshell.rb

Overview

Windows oriented but platform independent file system abstraction.

Direct Known Subclasses

WinShell

Instance Method Summary collapse

Constructor Details

#initializeShellInterface

Returns a new instance of ShellInterface.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/piggy-core/winshell.rb', line 8

def initialize
  @special_folder_ids = {
    "ALTSTARTUP" => 0x1d,
    "APPDATA" => 0x1a,
    "COMMONALTSTARTUP" => 0x1e,
    "COMMONAPPDATA" => 0x23,
    "COMMONDESKTOPDIR" => 0x19,
    "COMMONFAVORITES" => 0x1f,
    "COMMONPROGRAMS" => 0x17,
    "COMMONSTARTMENU" => 0x16,
    "COMMONSTARTUP" => 0x18,
    "CONTROLS" => 0x3,
    "COOKIES" => 0x21,
    "DESKTOP" => 0x0,
    "DESKTOPDIRECTORY" => 0x10,
    "FAVORITES" => 0x6,
    "FONTS" => 0x14,
    "HISTORY" => 0x22,
    "INTERNETCACHE" => 0x20,
    "LOCALAPPDATA" => 0x1c,
    "MYPICTURES" => 0x27,
    "NETHOOD" => 0x13,
    "PERSONAL" => 0x5,
    "PRINTHOOD" => 0x1b,
    "PROFILE" => 0x28,
    "PROGRAMFILES" => 0x26,
    "PROGRAMS" => 0x2,
    "RECENT" => 0x8,
    "SENDTO" => 0x9,
    "STARTMENU" => 0xb,
    "STARTUP" => 0x7,
    "SYSTEM" => 0x25,
    "TEMPLATES" => 0x15,
    "WINDOWS" => 0x24
  }
  init_home
end

Instance Method Details

#desktop_directoryObject



92
93
94
# File 'lib/piggy-core/winshell.rb', line 92

def desktop_directory
  return path_for_special_folder("DESKTOPDIRECTORY")
end

#escape(pathString) ⇒ Object

for use in commandline execution



73
74
75
# File 'lib/piggy-core/winshell.rb', line 73

def escape(pathString)
  return pathString
end

#has_extension?(filename, ext) ⇒ Boolean

Has filename the Extension ext (e. g. “.jpg”)

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


118
119
120
121
122
123
# File 'lib/piggy-core/winshell.rb', line 118

def has_extension?(filename, ext)
  raise ArgumentError, "Extension missing" if ext.empty?
  p_ext = (ext[0] == '.'[0] ? ext : '.' + ext).downcase
  dc_filename = filename.downcase
  return File.basename(dc_filename, p_ext) != File.basename(dc_filename)
end

#init_homeObject



46
47
48
49
50
51
52
53
# File 'lib/piggy-core/winshell.rb', line 46

def init_home
  @home = ENV['HOME']
  @home = ENV['HOMEPATH'] unless @home
  unless @home
    puts 'ShellInterface could not set @home - using /'   
    @home = '/'
  end
end

#link?(filename) ⇒ Boolean

Is filename a Windows shortcut? - Default: no file is a shortcut

Returns:

  • (Boolean)


113
114
115
# File 'lib/piggy-core/winshell.rb', line 113

def link?(filename)
  return false
end

#os_path(pathString) ⇒ Object

platform dependent path (no better default possible)



68
69
70
# File 'lib/piggy-core/winshell.rb', line 68

def os_path(pathString)
  return win_path(pathString)
end

#path_for_special_folder(name) ⇒ Object

try to provide a platform independent default



56
57
58
# File 'lib/piggy-core/winshell.rb', line 56

def path_for_special_folder(name)
  return @home
end

#picture_directoryObject



88
89
90
# File 'lib/piggy-core/winshell.rb', line 88

def picture_directory
  return path_for_special_folder("MYPICTURES")
end

#remove_path(filename_with_path) ⇒ Object



108
109
110
# File 'lib/piggy-core/winshell.rb', line 108

def remove_path(filename_with_path)
  return ruby_path(filename_with_path).split(separator)[-1]
end

#ruby_path(pathString) ⇒ Object

Get a path string usable by common ruby classes such as Dir and File. Default: convert ‘' to ’/‘ on all systems, even on Unix



84
85
86
# File 'lib/piggy-core/winshell.rb', line 84

def ruby_path(pathString)
  return pathString.gsub(/\\/, separator).gsub(/^~/, @home)
end

#separatorObject

Get the path separator used by common ruby classes such as Dir and File.



104
105
106
# File 'lib/piggy-core/winshell.rb', line 104

def separator
  return File::SEPARATOR
end

#special_folder_listingObject



96
97
98
99
100
101
# File 'lib/piggy-core/winshell.rb', line 96

def special_folder_listing
  @special_folder_ids.keys.sort.each do |aFolder|
    printf "#{aFolder}: "
    puts "#{path_for_special_folder aFolder}"
  end
end

#tmp_pathObject



60
61
62
63
64
65
# File 'lib/piggy-core/winshell.rb', line 60

def tmp_path
  tmp = ENV['TEMP']
  tmp = ENV['TMP'] unless tmp
  tmp = '/' unless tmp
  return tmp
end

#win_path(pathString) ⇒ Object

old name, use os_path instead



78
79
80
# File 'lib/piggy-core/winshell.rb', line 78

def win_path(pathString)
  return pathString
end