<commit_before>%w[
  fontina
  fiddle
  fiddle/import
  fiddle/types
].each { |lib| require lib }

%w[
  version
  language_codes
  marshal
  win32
  package
  meta_package
  install
].each { |file| require "fontina/windows/#{file}" }

module Fontina::Windows
  include Win32
  extend Marshal

  def self.system_language
    @system_language ||= LANGUAGE_CODES.fetch Kernel32.GetSystemDefaultUILanguage()
  end

  def self.fonts_directory
    @fonts_directory ||= Shell32.SHGetFolderPathW(CSIDL_FONTS).encode('filesystem').freeze
  end

  def self.registered_fonts
    key = Advapi32.RegOpenKeyExW(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', KEY_READ)
    begin
      Advapi32.RegQueryInfoKeyW(key)
        .tap do |info|
          break info.value_count.times.map do |i|
            Advapi32.RegEnumValueW(key, i, name_len: info.max_name_len + 1, data_len: info.max_data_len)
          end
        end
        .reject { |value| value.type != REG_SZ }
        .map { |value| [value.name, wstr!(value.data).rstrip.encode('filesystem')] }
        .to_h
    ensure
      Advapi32.RegCloseKey(key)
    end
  end

  def self.add_font_resource(path)
    Gdi32.AddFontResourceW(path).tap do |count|
      User32.PostMessageW(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) if 0 < count
    end
  end

  def self.register_font(name, path)
    key = Advapi32.RegOpenKeyExW(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', KEY_WRITE)
    begin
      Advapi32.RegSetValueExW(key, name, REG_SZ, wstr(path) + wchar(0))
    ensure
      Advapi32.RegCloseKey(key)
    end
  end

end
<commit_msg>use require_relative to load lib files<commit_after>%w[
  fontina
  fontina/windows/language_codes
  fiddle
  fiddle/import
  fiddle/types
].each { |lib| require lib }

%w[
  version
  marshal
  win32
  package
  meta_package
  install
].each { |file| require_relative "windows/#{file}" }

module Fontina::Windows
  include Win32
  extend Marshal

  def self.system_language
    @system_language ||= LANGUAGE_CODES.fetch Kernel32.GetSystemDefaultUILanguage()
  end

  def self.fonts_directory
    @fonts_directory ||= Shell32.SHGetFolderPathW(CSIDL_FONTS).encode('filesystem').freeze
  end

  def self.registered_fonts
    key = Advapi32.RegOpenKeyExW(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', KEY_READ)
    begin
      Advapi32.RegQueryInfoKeyW(key)
        .tap do |info|
          break info.value_count.times.map do |i|
            Advapi32.RegEnumValueW(key, i, name_len: info.max_name_len + 1, data_len: info.max_data_len)
          end
        end
        .reject { |value| value.type != REG_SZ }
        .map { |value| [value.name, wstr!(value.data).rstrip.encode('filesystem')] }
        .to_h
    ensure
      Advapi32.RegCloseKey(key)
    end
  end

  def self.add_font_resource(path)
    Gdi32.AddFontResourceW(path).tap do |count|
      User32.PostMessageW(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) if 0 < count
    end
  end

  def self.register_font(name, path)
    key = Advapi32.RegOpenKeyExW(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', KEY_WRITE)
    begin
      Advapi32.RegSetValueExW(key, name, REG_SZ, wstr(path) + wchar(0))
    ensure
      Advapi32.RegCloseKey(key)
    end
  end

end

{'fraction_non_alphanumeric': 0.1006079027355623, 'fraction_numerical': 0.01884498480243161, 'mean_word_length': 3.324572930354796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3673222', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1169, 'n_words': 223}