forked from lifegpc/bili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoopenlist.py
53 lines (48 loc) · 1.84 KB
/
autoopenlist.py
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
# (C) 2019-2020 lifegpc
# This file is part of bili.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from os.path import abspath, exists, isfile
from platform import system
from inspect import currentframe
if system() == "Windows":
from win32com.shell import shell # pylint: disable=import-error no-name-in-module
class autoopenfilelist:
__fl = None
__logg = None
def __init__(self, logg=None):
self.__fl = []
self.__logg = logg
def add(self, fn: str):
r = abspath(fn)
self.__fl.append(r)
if self.__logg is not None:
self.__logg.write(
f"Add '{r}' to download file list.", currentframe(), "Auto Open File List Add")
def open(self):
i = len(self.__fl) - 1
r = ""
while i >= 0:
fn = self.__fl[i]
if exists(fn) and isfile(fn):
r = fn
break
i = i - 1
if r != "":
if system() == "Windows":
if self.__logg is not None:
self.__logg.write(
f"Try open '{r}'.", currentframe(), "Auto Open File List Open")
d = shell.SHParseDisplayName(r, 0)
shell.SHOpenFolderAndSelectItems(d[0], [], 0)