LINUX.ORG.RU

История изменений

Исправление Novator, (текущая версия) :

Оказалось, что в винде «start C:\User\Path» не открывает в проводнике папку. Пришлось снова костылять и получилась вот такая кроссплатформенная штука на Ruby (поддерживающая кириллицу в путях!), открывающая и папки, и url, и в винде, и в линуксе:

  CP_UTF8        = 65001
  $waMultiByteToWideChar = nil

  # Convert UTF8 to Unicode in Windows
  # RU: Конвертировать UTF8 в Юникод в Винде
  def self.win_utf8_to_unicode(str)
    if init_win32api
      $waMultiByteToWideChar ||= Win32API.new('kernel32', \
        'MultiByteToWideChar', ['I','L','S','I','P','I'], 'I')
      if $waMultiByteToWideChar
        str = str.dup
        str.force_encoding('UTF-8')
        len = $waMultiByteToWideChar.call(CP_UTF8, 0, str, -1, nil, 0)
        if (len.is_a? Integer) and (len>0)
          buf = 0.chr * len * 2
          len = $waMultiByteToWideChar.call(CP_UTF8, 0, str, -1, buf, len)
          str = buf if (len.is_a? Integer) and (len>0)
        end
      end
    end
    str
  end

  $waShellExecute = nil

  # Open in Windows
  # RU: Открыть в Винде
  def self.win_shell_execute(link, oper=nil)
    #oper = :edit, :find, :open, :print, :properties
    res = nil
    if init_win32api
      link = win_utf8_to_unicode(link)
      $waShellExecute ||= Win32API.new('shell32', 'ShellExecuteW', \
        ['L', 'P', 'P', 'P', 'P', 'L'], 'L')
      if $waShellExecute
        oper = win_utf8_to_unicode(oper.to_s) if oper
        puts 'win_shell_execute [link, oper]='+[link, oper].inspect
        res = $waShellExecute.call(0, oper, link, nil, nil, SW_SHOW)
        res = ((res.is_a? Numeric) and ((res == 33) or (res == 42)))
      end
    end
    res
  end

  # Open link in web browser, email client or file manager
  # RU: Открывает ссылку в браузере, почтовике или проводнике
  def self.external_open(link, oper=nil)
    if PandoraUtils.os_family=='windows'
      PandoraUtils.win_shell_execute(link, oper)
    else
      pid = Process.spawn('xdg-open', link)
      Process.detach(pid) if pid
    end
  end

Исправление Novator, :

Оказалось, что в винде «start C:\User\Path» не открывает в проводнике папку. Пришлось снова костылять и получилась вот такая кроссплатформенная штука на Ruby (поддерживающая кириллицу в путях!), открывающая и папки, и url, и в винде, и в линуксе:

  CP_UTF8        = 65001
  $waMultiByteToWideChar = nil

  # Convert UTF8 to Unicode in Windows
  # RU: Конвертировать UTF8 в Юникод в Винде
  def self.win_utf8_to_unicode(str)
    if init_win32api
      $waMultiByteToWideChar ||= Win32API.new('kernel32', \
        'MultiByteToWideChar', ['I','L','S','I','P','I'], 'I')
      if $waMultiByteToWideChar
        str = str.dup
        str.force_encoding('UTF-8')
        codep = CP_UTF8
        len = $waMultiByteToWideChar.call(codep, 0, str, -1, nil, 0)
        if (len.is_a? Integer) and (len>0)
          buf = 0.chr * len * 2
          len = $waMultiByteToWideChar.call(codep, 0, str, -1, buf, len)
          str = buf if (len.is_a? Integer) and (len>0)
        end
      end
    end
    str
  end

  $waShellExecute = nil

  # Open in Windows
  # RU: Открыть в Винде
  def self.win_shell_execute(link, oper=nil)
    #oper = :edit, :find, :open, :print, :properties
    res = nil
    if init_win32api
      link = win_utf8_to_unicode(link)
      $waShellExecute ||= Win32API.new('shell32', 'ShellExecuteW', \
        ['L', 'P', 'P', 'P', 'P', 'L'], 'L')
      if $waShellExecute
        oper = win_utf8_to_unicode(oper.to_s) if oper
        puts 'win_shell_execute [link, oper]='+[link, oper].inspect
        res = $waShellExecute.call(0, oper, link, nil, nil, SW_SHOW)
        res = ((res.is_a? Numeric) and ((res == 33) or (res == 42)))
      end
    end
    res
  end

  # Open link in web browser, email client or file manager
  # RU: Открывает ссылку в браузере, почтовике или проводнике
  def self.external_open(link, oper=nil)
    if PandoraUtils.os_family=='windows'
      PandoraUtils.win_shell_execute(link, oper)
    else
      pid = Process.spawn('xdg-open', link)
      Process.detach(pid) if pid
    end
  end

Исправление Novator, :

CP_UTF8 = 65001 $waMultiByteToWideChar = nil

# Convert UTF8 to Unicode in Windows # RU: Конвертировать UTF8 в Юникод в Винде def self.win_utf8_to_unicode(str) if init_win32api $waMultiByteToWideChar ||= Win32API.new('kernel32', \ 'MultiByteToWideChar', ['I','L','S','I','P','I'], 'I') if $waMultiByteToWideChar str = str.dup str.force_encoding('UTF-8') codep = CP_UTF8 len = $waMultiByteToWideChar.call(codep, 0, str, -1, nil, 0) if (len.is_a? Integer) and (len>0) buf = 0.chr * len * 2 len = $waMultiByteToWideChar.call(codep, 0, str, -1, buf, len) str = buf if (len.is_a? Integer) and (len>0) end end end str end

$waShellExecute = nil

# Open in Windows # RU: Открыть в Винде def self.win_shell_execute(link, oper=nil) #oper = :edit, :find, :open, :print, :properties res = nil if init_win32api link = win_utf8_to_unicode(link) $waShellExecute ||= Win32API.new('shell32', 'ShellExecuteW', \ ['L', 'P', 'P', 'P', 'P', 'L'], 'L') if $waShellExecute oper = win_utf8_to_unicode(oper.to_s) if oper puts 'win_shell_execute [link, oper]='+[link, oper].inspect res = $waShellExecute.call(0, oper, link, nil, nil, SW_SHOW) res = ((res.is_a? Numeric) and ((res == 33) or (res == 42))) end end res end

# Open link in web browser, email client or file manager # RU: Открывает ссылку в браузере, почтовике или проводнике def self.external_open(link, oper=nil) if PandoraUtils.os_family=='windows' PandoraUtils.win_shell_execute(link, oper) else pid = Process.spawn('xdg-open', link) Process.detach(pid) if pid end end

Исходная версия Novator, :

Оказалось, что в винде «start C:\User\Path» не открывает в проводнике папку. Пришлось снова костылять и получилась вот такая кроссплатформенная штука на Ruby (поддерживающая кириллицу в путях!), открывающая и папки, и url, и в винде, и в линуксе:

  CP_UTF8        = 65001          
  $waMultiByteToWideChar = nil
  
  # Convert UTF8 to Unicode in Windows
  # RU: Конвертировать UTF8 в Юникод в Винде
  def self.win_utf8_to_unicode(str)
    if init_win32api  
      $waMultiByteToWideChar ||= Win32API.new('kernel32', \
        'MultiByteToWideChar', ['I','L','S','I','P','I'], 'I')
      if $waMultiByteToWideChar
        str = str.dup
        str.force_encoding('UTF-8')
        codep = CP_UTF8
        len = $waMultiByteToWideChar.call(codep, 0, str, -1, nil, 0)
		if (len.is_a? Integer) and (len>0)
          buf = 0.chr * len * 2
          len = $waMultiByteToWideChar.call(codep, 0, str, -1, buf, len)
          str = buf if (len.is_a? Integer) and (len>0)
        end                    
      end
    end
    str
  end
  
  $waShellExecute = nil

  # Open in Windows
  # RU: Открыть в Винде
  def self.win_shell_execute(link, oper=nil)
    #oper = :edit, :find, :open, :print, :properties
    res = nil
    if init_win32api
      link = win_utf8_to_unicode(link)      
      $waShellExecute ||= Win32API.new('shell32', 'ShellExecuteW', \
        ['L', 'P', 'P', 'P', 'P', 'L'], 'L')
      if $waShellExecute
        if oper
          oper = oper.to_s 
          oper = win_utf8_to_unicode(oper)      
        end
        res = $waShellExecute.call(0, oper, link, nil, nil, SW_SHOW)
        res = ((res.is_a? Numeric) and ((res == 33) or (res == 42)))
      end
    end
    res
  end

  # Open link in web browser, email client or file manager
  # RU: Открывает ссылку в браузере, почтовике или проводнике
  def self.external_open(link, oper=nil)
    if PandoraUtils.os_family=='windows'
      PandoraUtils.win_shell_execute(link, oper)
    else
      pid = Process.spawn('xdg-open', link)
      Process.detach(pid) if pid
    end
  end