Skip to content

Commit 5099669

Browse files
committed
ui
1 parent bdab7ce commit 5099669

2 files changed

Lines changed: 44 additions & 11 deletions

File tree

src/UI_instance/UI_Model/zippanel.ui

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>796</width>
10-
<height>611</height>
9+
<width>1016</width>
10+
<height>684</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -29,7 +29,7 @@
2929
</sizepolicy>
3030
</property>
3131
<property name="text">
32-
<string>选择Serval文件</string>
32+
<string>Select Serval File</string>
3333
</property>
3434
</widget>
3535
</item>
@@ -42,7 +42,14 @@
4242
</sizepolicy>
4343
</property>
4444
<property name="text">
45-
<string>选择7z程序位置</string>
45+
<string>Select 7z.exe File</string>
46+
</property>
47+
</widget>
48+
</item>
49+
<item>
50+
<widget class="QCheckBox" name="checkUsing7z">
51+
<property name="text">
52+
<string>Use Internal Zipfile tool instead</string>
4653
</property>
4754
</widget>
4855
</item>
@@ -55,7 +62,7 @@
5562
</sizepolicy>
5663
</property>
5764
<property name="text">
58-
<string>选择保存位置</string>
65+
<string>Select Save Path</string>
5966
</property>
6067
</widget>
6168
</item>
@@ -68,7 +75,7 @@
6875
</sizepolicy>
6976
</property>
7077
<property name="text">
71-
<string>开始打包</string>
78+
<string>Start Packing</string>
7279
</property>
7380
</widget>
7481
</item>

src/model/ZipUtil.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,47 @@ def __init__(self, ziptoolpath:str, zipfilepath:str):
1313
self.using7z=True
1414
if len(self.ziptoolpath)==0:
1515
self.using7z=False
16-
def getzipfile(self):
17-
if self.using7z:
18-
with open('blankfile','w') as f:
16+
def setpassword(self,password:str):
17+
self.password=password
18+
def getzipfile(self):#create a blank zip file
19+
if self.using7z: #using outside 7z.exe
20+
with open('blankfile','w') as f: #create a blankfile to compress
1921
f.write('\n')
20-
command=' a '+self.zipfilepath+' '+os.getcwd()+'\\blankfile -p'+ZIP_PASS
22+
command=' a '+self.zipfilepath+' '+os.getcwd()+'\\blankfile'
23+
if len(self.password)!=0:
24+
command += ' -p'+self.password
2125
print(self.ziptoolpath+command)
2226
code=os.system(self.ziptoolpath+command)
2327
return code
28+
else:#using zipfile pack, with no password
29+
try:
30+
azip = zipfile.ZipFile(self.zipfilepath, 'w')
31+
azip.write('blankfile', compress_type=zipfile.ZIP_LZMA)
32+
azip.close()
33+
return 0
34+
except Exception as e:
35+
azip.close()
36+
return str(e)
2437
def genzipfile(self,folder_path:str):
2538
if self.using7z:
2639
command=" a -t7z -scsUTF-8 "+self.zipfilepath+" "+folder_path+"\\* -p"+ZIP_PASS
2740
print(self.ziptoolpath+command)
2841
code = os.system(self.ziptoolpath + command)
2942
return code
30-
43+
else:
44+
try:
45+
azip = zipfile.ZipFile(self.zipfilepath, 'w')
46+
for current_path, subfolders, filesname in os.walk(folder_path):
47+
print(current_path, subfolders, filesname)
48+
# filesname是一个列表,我们需要里面的每个文件名和当前路径组合
49+
for file in filesname:
50+
# 将当前路径与当前路径下的文件名组合,就是当前文件的绝对路径
51+
azip.write(os.path.join(current_path, file))
52+
azip.close()
53+
return 0
54+
except Exception as e:
55+
azip.close()
56+
return str(e)
3157

3258
def load_serval(str_serval:str): #load a serval file
3359
lines=str_serval.split('\n')

0 commit comments

Comments
 (0)