ui/logic/data: refreshing only source files that have been updated
This change adds the refresh component that allows for refreshing the source code via UI or shortcut. If automatic refreshing is activated via the UI, the code is refreshed anytime the window gets focus. The contents of all the updated source files get removed from Storage, before reparsing them. File dependencies are not respected yet.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#include "utility/FileSystem.h"
|
||||
|
||||
#include "boost/date_time.hpp"
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
std::vector<std::string> FileSystem::getSourceFilesFromDirectory(
|
||||
std::vector<std::string> FileSystem::getFileNamesFromDirectory(
|
||||
const std::string& path, const std::vector<std::string>& extensions
|
||||
){
|
||||
)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
|
||||
if (boost::filesystem::is_directory(path))
|
||||
@@ -25,25 +25,37 @@ std::vector<std::string> FileSystem::getSourceFilesFromDirectory(
|
||||
return files;
|
||||
}
|
||||
|
||||
std::vector<std::string> FileSystem::getFileNamesFromDirectory(
|
||||
const std::string& path, const std::vector<std::string>& extensions
|
||||
)
|
||||
{
|
||||
return getSourceFilesFromDirectory(path, extensions);
|
||||
}
|
||||
std::vector<std::string> FileSystem::getFileNamesFromDirectoryUpdatedAfter(
|
||||
const std::string& path, const std::vector<std::string>& extensions, const std::string& timeString
|
||||
){
|
||||
std::vector<std::string> files;
|
||||
|
||||
bool FileSystem::isValidExtension(const std::string& filepath, const std::vector<std::string>& extensions)
|
||||
{
|
||||
boost::filesystem::path path(filepath);
|
||||
const boost::posix_time::ptime time = boost::posix_time::from_iso_string(timeString);
|
||||
|
||||
for (std::string extension : extensions)
|
||||
if (boost::filesystem::is_directory(path))
|
||||
{
|
||||
if (path.extension() == extension)
|
||||
boost::filesystem::recursive_directory_iterator it(path);
|
||||
boost::filesystem::recursive_directory_iterator endit;
|
||||
while (it != endit)
|
||||
{
|
||||
return true;
|
||||
if (boost::filesystem::is_regular_file(*it) && isValidExtension(it->path().string(), extensions))
|
||||
{
|
||||
std::time_t t = boost::filesystem::last_write_time(*it);
|
||||
boost::posix_time::ptime lastWriteTime = boost::posix_time::from_time_t(t);
|
||||
if (lastWriteTime >= time)
|
||||
{
|
||||
files.push_back(it->path().generic_string());
|
||||
}
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return files;
|
||||
}
|
||||
|
||||
std::string FileSystem::getTimeStringNow()
|
||||
{
|
||||
return boost::posix_time::to_iso_string(boost::posix_time::second_clock::universal_time());
|
||||
}
|
||||
|
||||
bool FileSystem::exists(const std::string& path)
|
||||
@@ -64,4 +76,33 @@ std::string FileSystem::extension(const std::string& path)
|
||||
std::string FileSystem::filePathWithoutExtension(const std::string& path)
|
||||
{
|
||||
return boost::filesystem::path(path).replace_extension().generic_string();
|
||||
}
|
||||
}
|
||||
|
||||
std::string FileSystem::absoluteFilePath(const std::string& path)
|
||||
{
|
||||
return boost::filesystem::absolute(boost::filesystem::path(path)).generic_string();
|
||||
}
|
||||
|
||||
bool FileSystem::equivalent(const std::string& pathA, const std::string& pathB)
|
||||
{
|
||||
if (exists(pathA) && exists(pathB))
|
||||
{
|
||||
return boost::filesystem::equivalent(boost::filesystem::path(pathA), boost::filesystem::path(pathB));
|
||||
}
|
||||
|
||||
return boost::filesystem::path(pathA).compare(boost::filesystem::path(pathB)) == 0;
|
||||
}
|
||||
|
||||
bool FileSystem::isValidExtension(const std::string& filepath, const std::vector<std::string>& extensions)
|
||||
{
|
||||
boost::filesystem::path path(filepath);
|
||||
|
||||
for (std::string extension : extensions)
|
||||
{
|
||||
if (path.extension() == extension)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7,18 +7,20 @@
|
||||
class FileSystem
|
||||
{
|
||||
public:
|
||||
static std::vector<std::string> getSourceFilesFromDirectory( // TODO: Replace this with getFileNamesFromDirectory.
|
||||
const std::string& path, const std::vector<std::string>& extensions
|
||||
);
|
||||
|
||||
static std::vector<std::string> getFileNamesFromDirectory(
|
||||
const std::string& path, const std::vector<std::string>& extensions
|
||||
);
|
||||
const std::string& path, const std::vector<std::string>& extensions);
|
||||
static std::vector<std::string> getFileNamesFromDirectoryUpdatedAfter(
|
||||
const std::string& path, const std::vector<std::string>& extensions, const std::string& timeString);
|
||||
|
||||
static std::string getTimeStringNow();
|
||||
|
||||
static bool exists(const std::string& path);
|
||||
static std::string fileName(const std::string& path);
|
||||
static std::string extension(const std::string& path);
|
||||
static std::string filePathWithoutExtension(const std::string& path);
|
||||
static std::string absoluteFilePath(const std::string& path);
|
||||
|
||||
static bool equivalent(const std::string& pathA, const std::string& pathB);
|
||||
|
||||
private:
|
||||
static bool isValidExtension(const std::string& filepath, const std::vector<std::string>& extensions);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef MESSAGE_AUTO_REFRESH_CHANGED_H
|
||||
#define MESSAGE_AUTO_REFRESH_CHANGED_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
|
||||
class MessageAutoRefreshChanged: public Message<MessageAutoRefreshChanged>
|
||||
{
|
||||
public:
|
||||
MessageAutoRefreshChanged(bool enabled)
|
||||
: enabled(enabled)
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageAutoRefreshChanged";
|
||||
}
|
||||
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_AUTO_REFRESH_CHANGED_H
|
||||
@@ -6,8 +6,9 @@
|
||||
class MessageFinishedParsing: public Message<MessageFinishedParsing>
|
||||
{
|
||||
public:
|
||||
MessageFinishedParsing(float parseTime, size_t errorCount)
|
||||
: parseTime(parseTime)
|
||||
MessageFinishedParsing(size_t fileCount, float parseTime, size_t errorCount)
|
||||
: fileCount(fileCount)
|
||||
, parseTime(parseTime)
|
||||
, errorCount(errorCount)
|
||||
{
|
||||
}
|
||||
@@ -17,6 +18,7 @@ public:
|
||||
return "MessageFinishedParsing";
|
||||
}
|
||||
|
||||
size_t fileCount;
|
||||
float parseTime;
|
||||
size_t errorCount;
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define MESSAGE_REFRESH_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class MessageRefresh: public Message<MessageRefresh>
|
||||
{
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef MESSAGE_WINDOW_FOCUS_H
|
||||
#define MESSAGE_WINDOW_FOCUS_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
|
||||
class MessageWindowFocus: public Message<MessageWindowFocus>
|
||||
{
|
||||
public:
|
||||
MessageWindowFocus()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageWindowFocus";
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MESSAGE_WINDOW_FOCUS_H
|
||||
Reference in New Issue
Block a user