-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4ac265
commit ad7d9d7
Showing
5 changed files
with
120 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- coding: utf-8 -*- | ||
#Falcon device ctrl | ||
#Copyright (C) 2020 Yukio Nozawa <personal@nyanchangames.com> | ||
#Copyright (C) 2020 yamahubuki <itiro.ishino@gmail.com> | ||
#Note: All comments except these top lines will be written in Japanese. | ||
|
||
import win32file | ||
import pywintypes | ||
import ctypes | ||
import re | ||
|
||
import errorCodes | ||
|
||
from simpleDialog import dialog | ||
from logging import getLogger | ||
|
||
|
||
log=getLogger("falcon.deviceCtrl") | ||
falconHelper=ctypes.cdll.LoadLibrary("falconHelper.dll") | ||
falconHelper.ejectDevice.argtypes=[ctypes.c_char_p] | ||
|
||
def ejectDrive(driveLetter): | ||
|
||
try: | ||
deviceName=win32file.QueryDosDevice(driveLetter[0].upper()+":") | ||
except pywintypes.error as e: | ||
if e.winerror==2: | ||
return errorCodes.FILE_NOT_FOUND | ||
else: | ||
dialog(_("エラー"),e.strerror) | ||
#log.error(unknown error in"+e.funcname+". code="+e.winerror+" message="+e.strerror) | ||
return errorCodes.UNKNOWN | ||
|
||
deviceName=re.sub(r"\\Device\\([^\x00]+).*",r"\1",deviceName) | ||
|
||
try: | ||
handle=win32file.CreateFile( | ||
"\\\\.\\"+deviceName, | ||
win32file.GENERIC_WRITE | win32file.GENERIC_READ, | ||
0, #クローズするまで他からはOPENできない | ||
None, #セキュリティ関連の構造体 | ||
win32file.OPEN_EXISTING, #デバイスのOPENはこれじゃないとダメ | ||
0, | ||
None) | ||
except pywintypes.error as e: | ||
if e.winerror==32: | ||
return errorCodes.ACCESS_DENIED | ||
else: | ||
dialog(_("エラー"),e.strerror) | ||
#log.error(unknown error in"+e.funcname+". code="+e.winerror+" message="+e.strerror) | ||
return errorCodes.UNKNOWN | ||
|
||
#0x2D4808=IOCTL_STORAGE_EJECT_MEDIA | ||
ret=win32file.DeviceIoControl(handle,0x2D4808,None,None) | ||
|
||
handle.Close() | ||
|
||
return errorCodes.OK | ||
|
||
|
||
def EjectDevice(letter): | ||
log.debug("Trying to eject drive %s..." % letter) | ||
ret=falconHelper.ejectDevice(letter.encode('utf-8')) | ||
if ret==0: | ||
log.debug("Successfully ejected.") | ||
return errorCodes.OK | ||
else: | ||
log.debug("Failed to eject device (Error code: %d)" % ret) | ||
return errorCodes.UNKNOWN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
#Falcon common error codes | ||
#Copyright (C) 2019 Yukio Nozawa <personal@nyanchangames.com> | ||
#Copyright (C) 2020 yamahubuki <itiro.ishino@gmail.com> | ||
#Note: All comments except these top lines will be written in Japanese. | ||
|
||
""" | ||
エラーコードは、Falconの全体で共通です。ここに書かれているもの以外のエラーコードを定義してはいけません。 | ||
""" | ||
|
||
OK=0#成功(エラーなし) | ||
NOT_SUPPORTED=1#サポートされていない呼び出し | ||
BOUNDARY=2#協会に到達したためリジェクト | ||
FILE_NOT_FOUND=3#ファイルが存在しない | ||
PARSING_FAILED=4#パーシングエラー | ||
FATAL=5#続行不可能なエラー | ||
OK=0 #成功(エラーなし) | ||
NOT_SUPPORTED=1 #サポートされていない呼び出し | ||
BOUNDARY=2 #境界に到達したためリジェクト | ||
FILE_NOT_FOUND=3 #ファイルが存在しない | ||
PARSING_FAILED=4 #パーシングエラー | ||
FATAL=5 #続行不可能なエラー | ||
ACCESS_DENIED=6 #アクセス拒否 | ||
|
||
|
||
UNKNOWN=99999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters