Skip to content

Commit d873cb2

Browse files
author
xxx
committed
support Cathy database V8 import
1 parent 3e82aaa commit d873cb2

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

src/librer.py

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,7 +2746,7 @@ def caf_import(self,pathcatname):
27462746
from binascii import b2a_hex
27472747
from struct import calcsize, unpack
27482748

2749-
DEBUG = True
2749+
l_info(f"caf_import:{pathcatname}")
27502750

27512751
ulModus = 1000000000
27522752
ulMagicBase = 500410407
@@ -2787,30 +2787,30 @@ def readstring():
27872787
m_sVersion = int(ul/ulModus)
27882788
else:
27892789
buffer.close()
2790-
print("Incorrect magic number for caf file",pathcatname, "(", ul % ulModus, ")")
2790+
l_info("Incorrect magic number for caf file",pathcatname, "(", ul % ulModus, ")")
27912791
return
27922792

27932793
if m_sVersion > 2:
27942794
m_sVersion = readbuf('h') # 2 bytes
27952795

2796-
#print(f'{m_sVersion=}')
2796+
l_info(f'{m_sVersion=}')
27972797

27982798
if m_sVersion > sVersion:
2799-
print("Incompatible caf version for", pathcatname, "(", m_sVersion, ")")
2799+
l_info("Incompatible caf version for", pathcatname, "(", m_sVersion, ")")
28002800
return
28012801

28022802
m_timeDate = readbuf('<L') # 4 bytes
2803-
#print(f'{m_timeDate=}')
2803+
l_info(f'{m_timeDate=}')
28042804

28052805
if m_sVersion >= 2:
28062806
m_strDevice = readstring()
2807-
#print(f'{m_strDevice=}')
2807+
l_info(f'{m_strDevice=}')
28082808

28092809
m_strVolume = readstring()
2810-
#print(f'{m_strVolume=}')
2810+
l_info(f'{m_strVolume=}')
28112811

28122812
m_strAlias = readstring()
2813-
#print(f'{m_strAlias=}')
2813+
l_info(f'{m_strAlias=}')
28142814

28152815
# m_dwSerialNumber well, odd..
28162816
bytesn = buffer.read(4) # 4 bytes
@@ -2822,33 +2822,33 @@ def readstring():
28222822
sn += chunk
28232823
m_dwSerialNumber = '%s-%s' % (sn[:4], sn[4:])
28242824

2825-
#print(f'{m_dwSerialNumber=}')
2825+
l_info(f'{m_dwSerialNumber=}')
28262826

28272827
if m_sVersion >= 4:
28282828
m_strComment = readstring()
2829-
#print(f'{m_strComment=}')
2829+
l_info(f'{m_strComment=}')
28302830

28312831
# m_fFreeSize - Starting version 1 the free size was saved
28322832
if m_sVersion >= 1:
28332833
m_fFreeSize = readbuf('<f') # as megabytes (4 bytes)
28342834
else:
28352835
m_fFreeSize = -1 # unknow
28362836

2837-
#print(f'{m_fFreeSize=}')
2837+
l_info(f'{m_fFreeSize=}')
28382838

28392839
if m_sVersion >= 6:
28402840
m_sArchive = readbuf('h') # 2 bytes
28412841
if m_sArchive == -1:
28422842
m_sArchive = 0
28432843

2844-
#print(f'{m_sArchive=}')
2844+
l_info(f'{m_sArchive=}')
28452845

28462846
caf_folders_dict={}
28472847

2848-
28492848
#########################################################
28502849
lLen = readbuf('<l') # 4 bytes
2851-
#print(f"Folders:{lLen}")
2850+
l_info(f"Folders:{lLen}")
2851+
28522852
for l in range(lLen):
28532853
if l == 0 or m_sVersion <= 3:
28542854
m_pszName = readstring()
@@ -2865,18 +2865,27 @@ def readstring():
28652865

28662866
#########################################################
28672867
lLen = readbuf('<l') # 4 bytes
2868-
#print(f"Files{lLen}")
2868+
l_info(f"Files:{lLen}")
2869+
28692870
for l in range(lLen):
28702871
date = readbuf('<L')
2871-
m_lLength=readbuf('<l')
2872-
m_sPathId = readbuf('H')
2873-
m_pszName = readstring()
2872+
if m_sVersion <= 6:
2873+
m_lLength=readbuf('<l')
2874+
m_sPathId = readbuf('H')
2875+
elif m_sVersion == 8:
2876+
m_lLength=readbuf('<q')
2877+
m_sPathId = readbuf('<L')
2878+
else:
2879+
l_info("m_sVersion:",m_sVersion)
2880+
l_info("Aborting")
2881+
break
28742882

2883+
m_pszName = readstring()
28752884
caf_names_dict[m_sPathId].add( (date, m_lLength, m_pszName) )
28762885

28772886
buffer.close()
28782887

2879-
return m_timeDate, m_strDevice, m_strVolume, m_strAlias, m_dwSerialNumber, m_strComment, m_fFreeSize, m_sArchive, caf_folders_dict, caf_names_dict
2888+
return m_sVersion, m_timeDate, m_strDevice, m_strVolume, m_strAlias, m_dwSerialNumber, m_strComment, m_fFreeSize, m_sArchive, caf_folders_dict, caf_names_dict
28802889

28812890
@restore_status_line
28822891
@block
@@ -2934,11 +2943,11 @@ def record_import_caf(self):
29342943
postfix=0
29352944

29362945
for filename in import_filenames:
2937-
m_timeDate, m_strDevice, m_strVolume, m_strAlias, m_dwSerialNumber, m_strComment, m_fFreeSize, m_sArchive, caf_folders_dict, caf_names_dict = self.caf_import(filename)
2946+
m_sVersion, m_timeDate, m_strDevice, m_strVolume, m_strAlias, m_dwSerialNumber, m_strComment, m_fFreeSize, m_sArchive, caf_folders_dict, caf_names_dict = self.caf_import(filename)
29382947

29392948
m_timeStr = strftime('%Y/%m/%d %H:%M:%S',localtime_catched(m_timeDate))
29402949

2941-
caf_info=f'Imported from "Cathy" database: {filename}\n----------------+------------------------------------------------------------------------------------------------\n creation time : {m_timeStr}\n device : {m_strDevice}\n volume : {m_strVolume}\n alias : {m_strAlias}\n serial number : {m_dwSerialNumber}\n comment : {m_strComment}\n free size : {m_fFreeSize}\n archive : {m_sArchive}\n----------------+------------------------------------------------------------------------------------------------'
2950+
caf_info=f'Imported from "Cathy" database: {filename}\n----------------+------------------------------------------------------------------------------------------------\n version : {m_sVersion}\n creation time : {m_timeStr}\n device : {m_strDevice}\n volume : {m_strVolume}\n alias : {m_strAlias}\n serial number : {m_dwSerialNumber}\n comment : {m_strComment}\n free size : {m_fFreeSize}\n archive : {m_sArchive}\n----------------+------------------------------------------------------------------------------------------------'
29422951

29432952
filenames_set={elem[2] for dir_elems in caf_names_dict.values() for elem in dir_elems}
29442953

@@ -3242,8 +3251,15 @@ def show_tooltips_tree(self,event):
32423251
tooltip_list = [STR('scan path') + f' : {scan_path}']
32433252
tooltip_list.append(STR('subpath') + f' : {subpath}')
32443253

3254+
32453255
if item in self.item_to_data:
32463256
data_tuple = self.item_to_data[item]
3257+
(entry_name,code,size,mtime) = data_tuple[0:4]
3258+
if size:
3259+
size_formatted = f"{size:,}".replace(",", " ")
3260+
3261+
tooltip_list.append(STR('size ') + f' : {bytes_to_str(size)} ({size_formatted} B)')
3262+
32473263
code = data_tuple[1]
32483264
is_dir,is_file,is_symlink,is_bind,has_cd,has_files,cd_ok,cd_aborted,cd_empty,aux2 = LUT_decode[code]
32493265

0 commit comments

Comments
 (0)