|
|
@@ -17,11 +17,17 @@ If you have any questions, please contact us: 1585346868@qq.com Or visit our web
|
|
|
|
|
|
#include "globalfuns.h"
|
|
|
#include <thread>
|
|
|
+#include <sys/stat.h>
|
|
|
+#include <filesystem>
|
|
|
+#include <chrono>
|
|
|
+#include <ctime>
|
|
|
+#include <iostream>
|
|
|
#include "util/counter.hpp"
|
|
|
#include "util/codec.h"
|
|
|
#include "util/time.h"
|
|
|
#include "util/system.h"
|
|
|
#include "core/global.h"
|
|
|
+#include "util/file.h"
|
|
|
#include "core/app.h"
|
|
|
#include "core/statemanager.h"
|
|
|
static ylib::counter<uint64> s_counter_guid;
|
|
|
@@ -99,6 +105,18 @@ int64 module::globalfuncs::now_msec()
|
|
|
{
|
|
|
return time::now_msec();
|
|
|
}
|
|
|
+std::string file_last_modify_time(const std::string& filepath)
|
|
|
+{
|
|
|
+ auto ftime = std::filesystem::last_write_time(filepath);
|
|
|
+ // 把 file_time_type 转为 system_clock::time_point
|
|
|
+ auto sctp = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
|
|
|
+ ftime - decltype(ftime)::clock::now() + std::chrono::system_clock::now()
|
|
|
+ );
|
|
|
+ // 转为 time_t(UNIX 时间戳)
|
|
|
+ last_modify_time = std::chrono::system_clock::to_time_t(sctp);
|
|
|
+ return last_modify_time;
|
|
|
+
|
|
|
+}
|
|
|
void module::globalfuncs::regist(sol::state* lua)
|
|
|
{
|
|
|
lua->set_function("fw_set_ptr", module::globalfuncs::set_ptr);
|
|
|
@@ -115,6 +133,7 @@ void module::globalfuncs::regist(sol::state* lua)
|
|
|
lua->set_function("fw_toint", module::globalfuncs::toint);
|
|
|
lua->set_function("fw_sleep_msec", module::globalfuncs::sleep_msec);
|
|
|
lua->set_function("fw_now_msec", module::globalfuncs::now_msec);
|
|
|
+ lua->set_function("fw_file_last_modify_time", module::globalfuncs::file_last_modify_time);
|
|
|
|
|
|
|
|
|
}
|