forked from Shirakumo/trial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos-resources.lisp
78 lines (65 loc) · 2.92 KB
/
os-resources.lisp
1
2
3
4
5
6
7
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
(in-package #:org.shirakumo.fraf.trial)
#+windows
(cffi:define-foreign-library secur32
(T (:default "Secur32")))
(defun system-username ()
(or #+windows
(cffi:with-foreign-objects ((size :ulong)
(name :uint16 128))
(unless (cffi:foreign-library-loaded-p 'secur32)
(cffi:load-foreign-library 'secur32))
(setf (cffi:mem-ref size :ulong) 128)
;; Constant 3 here specifies a "display name".
(cond ((< 0 (cffi:foreign-funcall "GetUserNameExW" :int 13 :pointer name :pointer size :int))
(org.shirakumo.com-on:wstring->string name (cffi:mem-ref size :ulong)))
(T
(setf (cffi:mem-ref size :ulong) 128)
(when (< 0 (cffi:foreign-funcall "GetUserNameW" :pointer name :pointer size :int))
(org.shirakumo.com-on:wstring->string name (cffi:mem-ref size :ulong))))))
#+unix
(cffi:foreign-funcall "getlogin" :string)
(pathname-utils:directory-name (user-homedir-pathname))))
(defvar *open-in-browser-hook* (constantly NIL))
(defun open-in-browser (url)
(or (funcall *open-in-browser-hook* url)
#+windows
(uiop:launch-program (list "rundll32" "url.dll,FileProtocolHandler" url))
#+linux
(uiop:launch-program (list "xdg-open" url))
#+darwin
(uiop:launch-program (list "open" url))))
(defun open-in-file-manager (path)
#+windows
(uiop:launch-program (list "explorer.exe" (uiop:native-namestring path)))
#+linux
(uiop:launch-program (list "xdg-open" (uiop:native-namestring path)))
#+darwin
(uiop:launch-program (list "open" (uiop:native-namestring path))))
(defun rename-thread (name)
#+windows
(com:with-wstring (name name)
(ignore-errors
(cffi:foreign-funcall "SetThreadDescription"
:size (cffi:foreign-funcall "GetCurrentThread" :size)
:string name
:size)))
#+unix
(ignore-errors
(cffi:foreign-funcall "pthread_setname_np"
:size (cffi:foreign-funcall "pthread_self" :size)
:string name
:int)))
(macrolet ((define-wrap (name fun)
`(progn
(defun ,name ()
(,fun))
(trivial-deprecate:declaim-deprecated (function ,name)
:software "trial"
:version "1.2.0"
:alternatives (,fun)))))
(define-wrap io-bytes org.shirakumo.machine-state:process-io-bytes)
(define-wrap cpu-time org.shirakumo.machine-state:process-time)
(define-wrap cpu-room org.shirakumo.machine-state:gc-room)
(define-wrap gpu-room org.shirakumo.machine-state:gpu-room)
(define-wrap gpu-time org.shirakumo.machine-state:gpu-time)
(define-wrap gc-time org.shirakumo.machine-state:gc-time))