Module: Bnicovideo::UserSession::Win95

Defined in:
lib/bnicovideo/user_session/win95.rb

Overview

Windows 95 and NT 4.x

Class Method Summary collapse

Class Method Details

.init_from_firefoxObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bnicovideo/user_session/win95.rb', line 12

def self.init_from_firefox
  # Single user only
  base_path = File.join(ENV['windir'], 'Application Data', 'Mozilla', 'Firefox')
  ini_path = File.join(base_path, 'profiles.ini')
  ini_hash = IniFile.load(ini_path).to_h
  profile_path = nil
  ini_hash.each do |k, v|
    next unless v['Name'] == 'default'
    relative = (v['IsRelative'] != '0')
    input_path = v['Path']
    if relative
      profile_path = File.join(base_path, input_path)
    else
      profile_path = input_path
    end
    sql_path = File.join(profile_path, 'cookies.sqlite')
    conn = SQLite3::Database.new(sql_path)
    val = conn.get_first_value("select value from moz_cookies" +
        " where host='.nicovideo.jp' AND name='user_session'")
    return val
  end
  return nil
end

.init_from_ieObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bnicovideo/user_session/win95.rb', line 35

def self.init_from_ie
  cookies_path = File.join(ENV['windir'], 'Cookie')
  Dir.open(cookies_path) do |dir|
    dir.each do |fn|
      next unless (/.*@nicovideo.*/ =~ fn)
      File.open(fn) do |f|
        cb = f.read
        cs = cb.split(/\*\n/)
        cs.each do |c|
          ca = c.split(/\n/)
          return ca[1] if ca[0] == 'user_session'
        end
      end
    end
  end
  return nil
end