mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-28 08:04:13 +08:00
unc
This commit is contained in:
parent
f004380daf
commit
c679924b03
@ -1,12 +1,16 @@
|
|||||||
import sys, os, io, time, threading, queue
|
import sys, os
|
||||||
from ctypes import windll, wintypes
|
from ctypes import windll, wintypes
|
||||||
|
|
||||||
|
|
||||||
def dopathexists(file):
|
def dopathexists(file: str):
|
||||||
|
import windows
|
||||||
|
|
||||||
if not file:
|
if not file:
|
||||||
return False
|
return False
|
||||||
if not file.strip():
|
if not file.strip():
|
||||||
return False
|
return False
|
||||||
|
if windows.check_unc_not_exists(file):
|
||||||
|
return False
|
||||||
PathFileExists = windll.Shlwapi.PathFileExistsW
|
PathFileExists = windll.Shlwapi.PathFileExistsW
|
||||||
PathFileExists.argtypes = (wintypes.LPCWSTR,)
|
PathFileExists.argtypes = (wintypes.LPCWSTR,)
|
||||||
PathFileExists.restype = wintypes.BOOL
|
PathFileExists.restype = wintypes.BOOL
|
||||||
|
@ -327,6 +327,35 @@ def GetLongPathName(file):
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def check_unc_file(v: str):
|
||||||
|
buf = create_unicode_buffer(65535)
|
||||||
|
for i in range(26):
|
||||||
|
A = chr(ord("A") + i) + ":"
|
||||||
|
if _QueryDosDeviceW(A, buf, 65535) != 0:
|
||||||
|
prefixdos = buf.value
|
||||||
|
if v.startswith(prefixdos):
|
||||||
|
return A + v[len(prefixdos) :]
|
||||||
|
# Get network drive
|
||||||
|
|
||||||
|
# 我操了,使用管理员权限时,这个玩意会失败
|
||||||
|
if _WNetGetUniversalNameW(A, 1, buf, byref(c_uint(65535))) == 0:
|
||||||
|
prefixnetwork = cast(
|
||||||
|
buf, POINTER(UNIVERSAL_NAME_INFO)
|
||||||
|
).contents.lpUniversalName
|
||||||
|
if v.startswith(prefixnetwork):
|
||||||
|
return A + v[len(prefixnetwork) :]
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def check_unc_not_exists(v: str):
|
||||||
|
# 当路径可能为unc路径,且不存在时,返回True
|
||||||
|
# 避免访问不存在unc路径时过长等待导致卡死
|
||||||
|
# (可能误伤)
|
||||||
|
if v.startswith("\\"):
|
||||||
|
return check_unc_file(v) is None
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _GetProcessFileName(hHandle):
|
def _GetProcessFileName(hHandle):
|
||||||
w = create_unicode_buffer(65535)
|
w = create_unicode_buffer(65535)
|
||||||
# 我佛了,太混乱了,不同权限获取的东西完全不一样
|
# 我佛了,太混乱了,不同权限获取的东西完全不一样
|
||||||
@ -340,28 +369,12 @@ def _GetProcessFileName(hHandle):
|
|||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
v = w.value
|
v: str = w.value
|
||||||
if v[0] == "\\":
|
|
||||||
|
if v.startswith("\\"):
|
||||||
buf = create_unicode_buffer(65535)
|
_f = check_unc_file(v)
|
||||||
for i in range(26):
|
if _f:
|
||||||
A = ord("A") + i
|
return _f
|
||||||
if _QueryDosDeviceW(chr(A) + ":", buf, 65535) != 0:
|
|
||||||
prefixdos = buf.value
|
|
||||||
if v.startswith(prefixdos):
|
|
||||||
v = chr(A) + ":" + v[len(prefixdos) :]
|
|
||||||
break
|
|
||||||
|
|
||||||
# Get network drive
|
|
||||||
|
|
||||||
# 我操了,使用管理员权限时,这个玩意会失败
|
|
||||||
if _WNetGetUniversalNameW(chr(A) + ":", 1, buf, byref(c_uint(65535))) == 0:
|
|
||||||
prefixnetwork = cast(
|
|
||||||
buf, POINTER(UNIVERSAL_NAME_INFO)
|
|
||||||
).contents.lpUniversalName
|
|
||||||
if v.startswith(prefixnetwork):
|
|
||||||
v = chr(A) + ":" + v[len(prefixnetwork) :]
|
|
||||||
break
|
|
||||||
return v
|
return v
|
||||||
else:
|
else:
|
||||||
return v
|
return v
|
||||||
|
@ -20,7 +20,7 @@ from ctypes import (
|
|||||||
c_long,
|
c_long,
|
||||||
)
|
)
|
||||||
from ctypes.wintypes import WORD, HWND, DWORD, RECT, UINT
|
from ctypes.wintypes import WORD, HWND, DWORD, RECT, UINT
|
||||||
import gobject
|
import gobject, windows
|
||||||
|
|
||||||
utilsdll = CDLL(gobject.GetDllpath(("winsharedutils32.dll", "winsharedutils64.dll")))
|
utilsdll = CDLL(gobject.GetDllpath(("winsharedutils32.dll", "winsharedutils64.dll")))
|
||||||
|
|
||||||
@ -198,6 +198,8 @@ _extracticon2data.restype = c_bool
|
|||||||
|
|
||||||
|
|
||||||
def extracticon2data(fname):
|
def extracticon2data(fname):
|
||||||
|
if windows.check_unc_not_exists(fname):
|
||||||
|
return None
|
||||||
ret = []
|
ret = []
|
||||||
|
|
||||||
def cb(ptr, size):
|
def cb(ptr, size):
|
||||||
|
@ -29,7 +29,7 @@ include(generate_product_version)
|
|||||||
|
|
||||||
set(VERSION_MAJOR 5)
|
set(VERSION_MAJOR 5)
|
||||||
set(VERSION_MINOR 53)
|
set(VERSION_MINOR 53)
|
||||||
set(VERSION_PATCH 9)
|
set(VERSION_PATCH 10)
|
||||||
|
|
||||||
add_library(pch pch.cpp)
|
add_library(pch pch.cpp)
|
||||||
target_precompile_headers(pch PUBLIC pch.h)
|
target_precompile_headers(pch PUBLIC pch.h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user