Page MenuHomeFeedback Tracker

Get Last Modified Time of files
Assigned, UrgentPublic

Description

I would like to suggest to add a new function to get the last modified time of a file, which can be useful in many different ways. For example

  • we could easily cleanup old player data files without having to save a timestamp in each json file in a banking mod.
  • Or it could be used to detect if a file was changed directly on the server and reload it automatically without having to load the whole file and checking if anything changed.

Details

Severity
Feature
Resolution
Open
Reproducibility
Always
Operating System
Windows 11 x64
Category
General
Steps To Reproduce

Add a function like
proto native bool GetLastModifiedFileTime(string filename, out int year, out int month, out int day, out int hour, out int minute, out int second)
proto native bool GetLastModifiedFileTimeUTC(string filename, out int year, out int month, out int day, out int hour, out int minute, out int second)

the method would return true if the file was found and a valid date is returned

Event Timeline

LBmaster created this task.Sep 5 2023, 10:18 AM
Geez changed the task status from New to Assigned.Sep 5 2023, 11:06 AM

A method to be able to query basic file structure variables like, name, last modified, date created, size.
Within one method resulting in a callback instance create that holds onto such parameters:

proto native FileQueryParams QueryFile(string path);

Or when going even further, you could implement a whole FileApi to subscribe to file changes with a callback to the reload any changed configs so for example

class FileApi {

	proto native static void SubscribtToFileChanges(string filename, FileChangeCallback callback);
	proto native static void UnsubscribeFromFileChanges(string filename); // Would remove all callbacks for this file
	proto native static void UnsubscribeFromFileChanges(FileChangeCallback callback); // Would remove this callback from all files
	proto native static void SubscribeToFolderChanges(string folder, FolderChangeCallback callback, bool recursive = false); // Allow to subscribe to folder changes. setting resursive to true would notify a callback about changes in subfolders and not only in the current folder
	proto native static void UnsubscribeFromFolderChanges(string folder); // Would remove all callbacks for this folder
	proto native static void UnsubscribeFromFolderChanges(FolderChangeCallback callback); // Would remove this callback from all folders
	
	// Maybe even move the rest of the file interaction here instead of global functions
	proto native static bool MakeDirectory(string name);
	proto native static bool DeleteFile(string name);
	proto native static bool CopyFile(string sourceName, string destName);
	
	proto static FindFileHandle FindFile(string pattern, out string fileName, out FileAttr fileAttributes, FindFileFlags flags);
	proto static bool FindNextFile(FindFileHandle handle, out string fileName, out FileAttr fileAttributes);
	proto native static void CloseFindFile(FindFileHandle handle);


	proto static int ReadFile(FileHandle file, void param_array, int length);

//...

}
class FileChangeCallback { // Scripts would create their own instances of their custom classes inheriting this base class and overwrite the methods
	
	void OnFileCreated(FileQueryParams info);
	void OnFileDeleted(string filename);
	void OnFileChanged(FileQueryParams oldInfo, FileQueryParams newInfo);
	
}
class FileQueryParams {
	
	string filename;
	int lastModifiedDate;
	int createdDate;
	int size;
	
}
class FileQueryChangeParams : FileQueryParams {
	
	FileEditSource editedBy = FileEditSource.UNKNOWN;
	
}
 // Scripts would create their own instances of their custom classes inheriting this base class and overwrite the methods
class FolderChangeCallback : FileChangeCallback { // Inherit the FileChangeCallback class, because all File events should also trigger when subscribed to the folder
	
	void OnFolderCreated(FileQueryParams folderInfo);
	void OnFolderDeleted(string foldername);
	void OnSubFolderCreated(FileQueryParams folderInfo);
	void OnSubFolderDeleted(string foldername);
	
}
enum FileEditSource {
	
	ENGINE, // Caused by the engine without any script interaction or at least not directly through the FileApi
	SCRIPT, // Initiated by another script via the FileApi
	SYSTEM // Initiated from any other source outside of the DayZ enviroment like 3rd party apps
	
}