16
16
from time import time
17
17
import hashlib
18
18
19
+ from PySide6 .QtCore import QDate , Qt
20
+
19
21
# Versions
20
- VERSION : str = "12-mar -2025"
21
- VERSION_SHORT : str = "1.2.1 "
22
+ VERSION : str = "25-apr -2025"
23
+ VERSION_SHORT : str = "2.0 "
22
24
# Versions of file formats
23
- FF_FILTER_VERSION = 1
25
+ FF_FILTER_VERSION = 2
24
26
FF_SEARCH_VERSION = 2
25
27
FF_SETTINGS_VERSION = 1
26
- FF_CACHE_VERSION = 2
28
+ FF_CACHE_VERSION = 3
27
29
28
30
# Defining folder variables and font sizes
29
31
USER_FOLDER = os .path .expanduser ("~" )
106
108
"display_menu_bar_icon" : True ,
107
109
"double_click_action" : "View file in Finder/File Explorer" }
108
110
111
+ DEFAULT_FILTER = {"VERSION" : FF_FILTER_VERSION ,
112
+ "name" : "" , "name_contains" : "" ,
113
+ "file_types" : FILE_FORMATS .keys (),
114
+ "file_extension" : "" , "file_type_mode" : "predefined" ,
115
+ "directory" : USER_FOLDER ,
116
+ "dates" : {"m_date_from" : "2000-01-01" , "c_date_from" : "2000-01-01" ,
117
+ "m_date_to" : QDate .currentDate ().toString (Qt .DateFormat .ISODate ),
118
+ "c_date_to" : QDate .currentDate ().toString (Qt .DateFormat .ISODate )},
119
+ "size" : {"min" : "" , "max" : "" }, "size_unit" : {"min" : "No Limit" , "max" : "No Limit" },
120
+ "folder_depth" : "Unlimited" , "folder_depth_custom" : 0 ,
121
+ "file_contains" : "" , "hidden_files" : False ,
122
+ "files_folders" : 0 , "sorting" : 0 , "reverse_sorting" : False }
123
+
109
124
# Color schemes
110
125
RED_LIGHT_THEME_COLOR = "#b1100c"
111
126
RED_DARK_THEME_COLOR = "#f27171"
@@ -125,14 +140,15 @@ def remove_cache():
125
140
126
141
127
142
# Convert a file path to the corresponding cache file or metadata
128
- def path_to_cache_file (path , metadata = False ):
143
+ def path_to_cache_file (path , depth , metadata = False ):
144
+ # A -1 for the depth means unlimited depth
129
145
if not metadata :
130
- return os .path .join (CACHED_SEARCHES_FOLDER , path .replace (os .sep , "-" ) + " .FFCache" )
146
+ return os .path .join (CACHED_SEARCHES_FOLDER , path .replace (os .sep , "-" ) + f"$ { depth } .FFCache" )
131
147
# If instead ask for metadata
132
148
elif metadata :
133
- return os .path .join (CACHE_METADATA_FOLDER , path .replace (os .sep , "-" ) + " .FFCache" )
149
+ return os .path .join (CACHE_METADATA_FOLDER , path .replace (os .sep , "-" ) + f"$ { depth } .FFCache" )
134
150
else :
135
- logging .fatal ("Wrong arguments used with the convert_path_to_cache_file() function in FF_Files.py" )
151
+ return logging .fatal ("Wrong arguments used with the convert_path_to_cache_file() function in FF_Files.py" )
136
152
137
153
138
154
# Takes a path to a cache file and returns the path to the metadata file
@@ -172,7 +188,7 @@ def cache_test(is_launching):
172
188
else :
173
189
logging .debug ("Skipping deleting..." )
174
190
175
- if cache_settings .lower () in ("after a Week " , "after a Day " , "after two hours" ):
191
+ if cache_settings .lower () in ("after a week " , "after a day " , "after two hours" ):
176
192
# Looping through every file in CACHED_SEARCHES_FOLDER and getting separately stored creation tie
177
193
# Iterating through all files in the cache folder
178
194
for file in os .listdir (CACHED_SEARCHES_FOLDER ):
@@ -204,7 +220,10 @@ def cache_test(is_launching):
204
220
205
221
# Function to get the File Size of a directory
206
222
def get_file_size (input_file : str ) -> int :
207
- if os .path .isdir (input_file ):
223
+ if os .path .islink (input_file ):
224
+ # Specific error code
225
+ return - 2
226
+ elif os .path .isdir (input_file ):
208
227
file_size_list_obj = 0
209
228
# Gets the size if the path is a folder with recursively searching th director<
210
229
for root , _dirs , files in os .walk (input_file ):
@@ -215,26 +234,23 @@ def get_file_size(input_file: str) -> int:
215
234
216
235
except (FileNotFoundError , ValueError ):
217
236
continue
237
+ return file_size_list_obj
218
238
elif os .path .isfile (input_file ):
219
239
try :
220
- file_size_list_obj = os .path .getsize (input_file )
240
+ return os .path .getsize (input_file )
221
241
except (FileNotFoundError , ValueError ):
222
242
return - 1
223
243
else :
224
- # Error code
244
+ # Error
225
245
return - 1
226
- if os .path .islink (input_file ):
227
- return - 2
228
- else :
229
- return file_size_list_obj
230
246
231
247
232
248
# Convert File Size to a String
233
249
def conv_file_size (byte_size : int , decimal_places = 2 ) -> str :
234
250
if byte_size == - 1 :
235
251
return "ERROR! (File does not exist or isn't valid)"
236
252
elif byte_size == - 2 :
237
- return "ERROR! ( File is a Link to an other File) "
253
+ return "File is a Link to an other File"
238
254
elif byte_size > 1000000000 :
239
255
return f"{ round (byte_size / 1000000000 , decimal_places )} GB"
240
256
elif byte_size > 1000000 :
@@ -285,6 +301,7 @@ def setup():
285
301
remove_cache ()
286
302
287
303
# Checking if all settings exist and updating version numbers
304
+ settings ["cache_version" ] = FF_CACHE_VERSION
288
305
settings ["settings_version" ] = FF_SETTINGS_VERSION
289
306
settings ["version" ] = f"{ VERSION_SHORT } [{ VERSION } ]"
290
307
0 commit comments