Skip to content

Commit

Permalink
#143 共有ドライブ内のオブジェクトの一覧表示に対応。まだ表示する以上の対応はしていない。各所の問題は後日修正する
Browse files Browse the repository at this point in the history
  • Loading branch information
yamahubuki committed Jul 9, 2020
1 parent 761e52f commit 4ab5607
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 62 deletions.
1 change: 1 addition & 0 deletions lists/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
from lists.stream import *
from lists.searchResult import *
from lists.grepResult import *
from lists.networkResource import *
from lists.constants import *
70 changes: 70 additions & 0 deletions lists/networkResource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
#Falcon networkResource list object
#Copyright (C) 2020 yamahubuki <itiro.ishino@gmail.com>
#Note: All comments except these top lines will be written in Japanese.

import wx
import win32wnet

import misc
import browsableObjects
import globalVars
import errorCodes

from simpleDialog import dialog
from .base import *
from .constants import *
from win32com.shell import shell, shellcon

class NetworkResourceList(FalconListBase):
"""ネットワークリソースの一覧を扱うクラス。"""
def __init__(self):
super().__init__()
self.supportedSorts=[] #ソート不可
self.columns={
_("名前"):wx.LIST_FORMAT_LEFT,
}
self.resources=[]
self.lists=[self.resources]

def Update(self):
return self.Initialize(self.rootDirectory,True)

def Initialize(self,path,silent=False):
"""リソースの情報を取得し、リストを初期化する。"""
self.log.debug("Getting resources list...")
self.rootDirectory=path
t=misc.Timer()
if isinstance(path,list):#パラメータがリストなら、browsableObjects のリストとして処理刷る(ファイルリストを取得しないでコピーする)
self.resources=path
return errorCodes.OK
#end copy
self.resources.clear()
if not silent:
globalVars.app.say(path[2:])

#取得対象を構造体にセット
rootResource=win32wnet.NETRESOURCE()
rootResource.lpRemoteName=path

#リソースリストの取得
try:
h=win32wnet.WNetOpenEnum(2,1,0,rootResource)
#2=RESOURCE_GLOBALNET
#1=RESOURCETYPE_DISK
lst=win32wnet.WNetEnumResource(h,64) #65以上の指定不可
win32wnet.WNetCloseEnum(h);
except win32net.error as er:
dialog(_("エラー"), _("ネットワーク上のリソース一覧を取得できませんでした(%(error)s)") % {"error": str(er)})
return errorCodes.ACCESS_DENIED

for l in lst:
ret, shfileinfo=shell.SHGetFileInfo(l.lpRemoteName,0,shellcon.SHGFI_ICON)
s=browsableObjects.NetworkResource()
self.log.debug("network resource found and check IP address:"+l.lpRemoteName[2:])
s.Initialize(l.lpRemoteName[len(path)+1:],l.lpRemoteName,"",shfileinfo[0])
self.resources.append(s)

self.log.debug("Network resource list created in %d seconds." % t.elapsed)
self.log.debug(str(len(self.resources))+" resources found.")
return errorCodes.OK
92 changes: 33 additions & 59 deletions tabs/NetworkResourceList.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
#Falcon NetworkResource List tab
#Copyright (C) 2020 yamahubuki <itiro.ishino@gmail.com>
#Falcon network resource List tab
#Copyright (C)2020 yamahubuki <itiro.ishino@gmail.com>
#Note: All comments except these top lines will be written in Japanese.

"""
ネットワークリソースリストです。ファイルリストと比べると、機能が制限されます
ネットワークリソースリストです。ファイル操作関連は一切できません
"""

import os
Expand Down Expand Up @@ -34,80 +34,54 @@ class NetworkResourceListTab(base.FalconTabBase):
"FILE_DELETE",
"FILE_MKDIR",
"EDIT_CUT",
"EDIT_PAST",
"EDIT_SEARCH",
"MOVE_BACKWARD",
"MOVE_FORWARD_TAB",
"MOVE_TOPFILE",
"TOOL_DIRCALC",
"TOOL_HASHCALC",
"TOOL_ADDPATH",
"READ_CONTENT_PREVIEW"
"TOOL_EXEC_PROGRAM",
"READ_CONTENT_PREVIEW",
"READ_CONTENT_READHEADER",
"READ_CONTENT_READFOOTER",
]

def Update(self,cursor=""):
"""指定された要素をタブに適用する。"""
self._cancelBackgroundTasks()
lst=lists.NetworkDeviceList()
lst.Initialize(None)
self.hListCtrl.DeleteAllItems()
self.SetListColumns(lst)
self.listObject=lst
self.UpdateListContent(self.listObject.GetItems())
if cursor!="":
c=lst.Search(cursor,0)
self.hListCtrl.Select(c)
self.hListCtrl.Focus(c)
#end カーソル初期位置を設定
#end Update

def GoBackward(self):
"""ドライブ一覧に戻る"""
return self.Move(""," ")
"""ドライブ一覧へ戻る"""
target=""
cursorTarget=self.listObject.rootDirectory[0]
return self.Move(target,cursorTarget)

def MakeShortcut(self,option):
prm=""
dir=""
if option["type"]=="shortcut":
prm=option["parameter"]
dir=option["directory"]
target=self.parent.activeTab.GetSelectedItems().GetElement(0).fullpath
dest=option["destination"]
if not os.path.isabs(dest): #早退の場合は絶対に直す
dest=os.path.normpath(os.path.join(os.path.dirname(target),dest))

#TODO:
#相対パスでの作成に後日対応する必要がある
#ハードリンクはドライブをまたげないのでバリデーションする
#ファイルシステムを確認し、対応してない種類のものは作れないようにバリデーションする
#作業フォルダの指定に対応する(ファイルオペレータ側の修正も必用)

if option["type"]=="shortcut":
inst={"operation":option["type"], "target": [(dest,target,prm)]}
else:
inst={"operation":option["type"], "from": [target], "to": [dest]}
#end ショートカットかそれ以外
op=fileOperator.FileOperator(inst)
ret=op.Execute()
if op.CheckSucceeded()==0:
dialog(_("エラー"),_("ショートカットの作成に失敗しました。"))
return
#end error
self.UpdateFilelist(silence=True)

def FileOperationTest(self):
if self.task:
self.task.Cancel()
else:
self.task=workerThreads.RegisterTask(workerThreadTasks.DebugBeep)
#TODO:リネームを拒否
def OnLabelEditEnd(self,event):
evt.Veto()
return

def ShowProperties(self):
index=self.GetFocusedItem()
shell.ShellExecuteEx(shellcon.SEE_MASK_INVOKEIDLIST,0,"properties",self.listObject.GetElement(index).fullpath)

def ReadCurrentFolder(self):
globalVars.app.say(_("現在は、ネットワーク上のリソースの洗濯"), interrupt=True)
globalVars.app.say(_("現在は、"+self.listObject.rootDirectory), interrupt=True)

def ReadListItemNumber(self):
globalVars.app.say(_("ネットワークリソース %(drives)d個") % {'drives': len(self.listObject)}, interrupt=True)
def ReadListItemNumber(self,short=False):
#shortもlongも関係ない
globalVars.app.say(_("項目数 %(count)d") % {'count': len(self.listObject)})

def ReadListInfo(self):
globalVars.app.say(_("ネットワークリソース一覧を %(sortkind)sの%(sortad)sで一覧中、 %(max)d個中 %(current)d個目") %{'sortkind': self.listObject.GetSortKindString(), 'sortad': self.listObject.GetSortAdString(), 'max': len(self.listObject), 'current': self.GetFocusedItem()+1}, interrupt=True)
globalVars.app.say(_("ネットワークリソースの一覧を一覧中、 %(max)d個中 %(current)d個目") %{'max': len(self.listObject), 'current': self.GetFocusedItem()+1}, interrupt=True)

def GetTabName(self):
"""タブコントロールに表示する名前"""
return self.listObject.rootDirectory

#TODO: def OpenContextMenu(self,event):

def GetRootObject(self):
"""ドライブ詳細情報表示で用いる"""
#TODO:IPアドレス入れる
return browsableObjects.NetworkResource(self.listObject.rootDirectory[2:],self.listObject.rootDirectory,None)
13 changes: 10 additions & 3 deletions tabs/navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import constants
import misc
import views.ViewCreator
from . import fileList,driveList,streamList,searchResult, grepResult
from . import fileList,driveList,streamList,searchResult,grepResult,NetworkResourceList
from simpleDialog import dialog

def Navigate(target,cursor="",previous_tab=None,create_new_tab_info=None,environment={}):
Expand Down Expand Up @@ -66,7 +66,14 @@ def Navigate(target,cursor="",previous_tab=None,create_new_tab_info=None,environ
return newtab
#end ドライブリストへ行く
target=os.path.expandvars(target)
if not os.path.exists(target):
if target[0:2]=="\\\\" and "\\" not in target[2:]:
lst=lists.NetworkResourceList()
result=lst.Initialize(target)
if result != errorCodes.OK:
return result #アクセス不可
newtab=NetworkResourceList.NetworkResourceListTab(environment)
newtab.Initialize(parent,creator,hListCtrl)
elif not os.path.exists(target):
dialog(_("エラー"),_("移動に失敗しました。移動先が存在しません。"))
return errorCodes.FILE_NOT_FOUND
elif os.path.isfile(target): #副ストリームへ移動
Expand All @@ -89,7 +96,7 @@ def Navigate(target,cursor="",previous_tab=None,create_new_tab_info=None,environ
dlg=wx.MessageDialog(None,_("アクセスが拒否されました。管理者としてFalconを別ウィンドウで立ち上げて再試行しますか?"),_("確認"),wx.YES_NO|wx.ICON_QUESTION)
if dlg.ShowModal()==wx.ID_YES:
misc.RunFile(sys.argv[0],True,target)
return result#アクセス負荷
return result#アクセス不可
if cursor!="":
targetItemIndex=lst.Search(cursor)
if type(previous_tab)==fileList.FileListTab:#再利用
Expand Down

0 comments on commit 4ab5607

Please sign in to comment.