LukaSJ0

Env

Oct 21st, 2020
705
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================
  2. #  Environment module for easy Win directory manipulation
  3. #===============================================================================
  4. module Env
  5.   #-----------------------------------------------------------------------------
  6.   # constant containing GUIDs found on MSDN for common directories
  7.   #-----------------------------------------------------------------------------
  8.   COMMON_PATHS = {
  9.       "CAMERA_ROLL" => "AB5FB87B-7CE2-4F83-915D-550846C9537B",
  10.       "START_MENU" => "A4115719-D62E-491D-AA7C-E74B8BE3B067",
  11.       "DESKTOP" => "B4BFCC3A-DB2C-424C-B029-7FE99A87C641",
  12.       "DOCUMENTS" => "FDD39AD0-238F-46AF-ADB4-6C85480369C7",
  13.       "DOWNLOADS" => "374DE290-123F-4565-9164-39C4925E467B",
  14.       "HOME" => "5E6C858F-0E22-4760-9AFE-EA3317B67173",
  15.       "MUSIC" => "4BD8D571-6D19-48D3-BE97-422220080E43",
  16.       "PICTURES" => "33E28130-4E1E-4676-835A-98395C3BC3BB",
  17.       "SAVED_GAMES" => "4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4",
  18.       "SCREENSHOTS" => "b7bede81-df94-4682-a7d8-57a52620b86f",
  19.       "VIDEOS" => "18989B1D-99B5-455B-841C-AB7C74E4DDFC",
  20.       "LOCAL" => "F1B32785-6FBA-4FCF-9D55-7B8E7F157091",
  21.       "LOCALLOW" => "A520A1A4-1780-4FF6-BD18-167343C5AF16",
  22.       "ROAMING" => "3EB685DB-65F9-4CF6-A03A-E3EF65729F3D",
  23.       "PROGRAM_DATA" => "62AB5D82-FDC1-4DC3-A9DD-070D1D495D97",
  24.       "PROGRAM_FILES_X64" => "6D809377-6AF0-444b-8957-A3773F02200E",
  25.       "PROGRAM_FILES_X86" => "7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E",
  26.       "COMMON_FILES" => "F7F1ED05-9F6D-47A2-AAAE-29D317C6F066",
  27.       "PUBLIC" => "DFDF76A2-C82A-4D63-906A-5644AC457385",
  28.   }
  29.   #-----------------------------------------------------------------------------
  30.   # escape chars for Directories
  31.   #-----------------------------------------------------------------------------
  32.   @char_set = {
  33.     "\\" => "&bs;", "/" => "&fs;", ":" => "&cn;", "*" => "&as;",
  34.     "?" => "&qm;", "\"" => "&dq;", "<" => "&lt;", ">" => "&gt;",
  35.     "|" => "&po;"
  36.   }
  37.   #-----------------------------------------------------------------------------
  38.   # returns directory path based on GUID
  39.   #-----------------------------------------------------------------------------
  40.   def self.path(type)
  41.     hex = self.guid_to_hex(COMMON_PATHS[type])
  42.     return getKnownFolder(hex)
  43.   end
  44.   #-----------------------------------------------------------------------------
  45.   # converts GUID to proper hex array
  46.   #-----------------------------------------------------------------------------
  47.   def self.guid_to_hex(string)
  48.     chunks = string.split("-")
  49.     hex = []
  50.     for i in 0...chunks.length
  51.       chunk = chunks[i]
  52.       if i < 3
  53.         hex.push(chunk.hex)
  54.       else
  55.         split = chunk.scan(/../)
  56.         for s in split
  57.           hex.push(s.hex)
  58.         end
  59.       end
  60.     end
  61.     return hex
  62.   end
  63.   #-----------------------------------------------------------------------------
  64.   # returns working directory
  65.   #-----------------------------------------------------------------------------
  66.   def self.directory
  67.     return Dir.pwd.gsub("/","\\")
  68.   end
  69.   #-----------------------------------------------------------------------------
  70.   # escape characters
  71.   #-----------------------------------------------------------------------------
  72.   def self.char_esc(str)
  73.     for key in @char_set.keys
  74.       str.gsub!(key, @char_set[key])
  75.     end
  76.     return str
  77.   end
  78.   #-----------------------------------------------------------------------------
  79.   # describe characters
  80.   #-----------------------------------------------------------------------------
  81.   def self.char_dsc(str)
  82.     for key in @char_set.keys
  83.       str.gsub!(@char_set[key], key)
  84.     end
  85.     return str
  86.   end
  87.   #-----------------------------------------------------------------------------
  88. end
RAW Paste Data