Skip to content

Commit

Permalink
Update to v0.50.18.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Jan 16, 2025
1 parent e94a32f commit e41ed96
Show file tree
Hide file tree
Showing 215 changed files with 2,188 additions and 1,510 deletions.
9 changes: 9 additions & 0 deletions ClientSource/Connection/BotBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ BotBaseContext::BotBaseContext(CancellableScope& parent, BotBase& botbase)
{
attach(parent);
}
BotBaseContext::BotBaseContext(CancellableScope& parent, BotBaseContext& context)
: m_botbase(context.botbase())
{
attach(parent);
}
BotBaseContext::~BotBaseContext(){
m_lifetime_sanitizer.check_usage();
try{
m_botbase.wait_for_all_requests(this);
}catch (...){}
detach();
}

Expand Down
1 change: 1 addition & 0 deletions ClientSource/Connection/BotBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class BotBaseContext final : public CancellableScope{
public:
BotBaseContext(BotBase& botbase);
BotBaseContext(CancellableScope& parent, BotBase& botbase);
BotBaseContext(CancellableScope& parent, BotBaseContext& context);
virtual ~BotBaseContext();


Expand Down
21 changes: 19 additions & 2 deletions Common/Cpp/Concurrency/ScheduledTaskRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,43 @@ ScheduledTaskRunner::~ScheduledTaskRunner(){
// ScheduledTaskRunner::cancel(nullptr);
{
std::lock_guard<std::mutex> lg(m_lock);
// cout << "ScheduledTaskRunner: (Destructor - start): " << this << endl;
m_stopped = true;
m_cv.notify_all();
}
m_runner.reset();
// cout << "ScheduledTaskRunner: (Destructor - end): " << this << endl;
}
ScheduledTaskRunner::ScheduledTaskRunner(AsyncDispatcher& dispatcher)
: m_stopped(false)
, m_runner(dispatcher.dispatch([this]{ thread_loop(); }))
{}
{
// cout << "ScheduledTaskRunner: (Constructor): " << this << endl;
}
size_t ScheduledTaskRunner::size() const{
std::lock_guard<std::mutex> lg(m_lock);
return m_schedule.size();
}
WallClock ScheduledTaskRunner::next_event() const{
std::lock_guard<std::mutex> lg(m_lock);
if (m_schedule.empty()){
if (m_stopped || m_schedule.empty()){
return WallClock::max();
}
return m_schedule.begin()->first;
}
void ScheduledTaskRunner::add_event(WallClock time, std::function<void()> callback){
std::lock_guard<std::mutex> lg(m_lock);
if (m_stopped){
return;
}
m_schedule.emplace(time, std::move(callback));
m_cv.notify_all();
}
void ScheduledTaskRunner::add_event(std::chrono::milliseconds time_from_now, std::function<void()> callback){
std::lock_guard<std::mutex> lg(m_lock);
if (m_stopped){
return;
}
m_schedule.emplace(current_time() + time_from_now, std::move(callback));
m_cv.notify_all();
}
Expand All @@ -62,6 +72,7 @@ bool ScheduledTaskRunner::cancel(std::exception_ptr exception) noexcept{
#endif
void ScheduledTaskRunner::thread_loop(){
std::unique_lock<std::mutex> lg(m_lock);
// cout << "ScheduledTaskRunner: (Starting thread loop): " << this << endl;
// WallClock last_check_timestamp = current_time();
while (!m_stopped){
#if 0
Expand All @@ -71,7 +82,9 @@ void ScheduledTaskRunner::thread_loop(){
#endif

if (m_schedule.empty()){
// cout << "ScheduledTaskRunner: (Sleeping): " << this << endl;
m_cv.wait(lg);
// cout << "ScheduledTaskRunner: (Waking): " << this << endl;
continue;
}

Expand All @@ -81,11 +94,15 @@ void ScheduledTaskRunner::thread_loop(){
m_cv.wait_until(lg, item->first);
continue;
}
// cout << "ScheduledTaskRunner: (task - start): " << this << endl;
lg.unlock();
item->second();
lg.lock();
// cout << "ScheduledTaskRunner: (task - end): " << this << endl;
m_schedule.erase(item);
}
// cout << "ScheduledTaskRunner: (Clearing schedule): " << this << endl;
m_schedule.clear();
}


Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ file(GLOB MAIN_SOURCES
Source/CommonFramework/Tools/SuperControlSession.h
Source/CommonFramework/Tools/VideoResolutionCheck.cpp
Source/CommonFramework/Tools/VideoResolutionCheck.h
Source/CommonFramework/Tools/VideoStream.cpp
Source/CommonFramework/Tools/VideoStream.h
Source/CommonFramework/VideoPipeline/Backends/CameraImplementations.cpp
Source/CommonFramework/VideoPipeline/Backends/CameraImplementations.h
Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt5.cpp
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/SerialPrograms.pro
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ SOURCES += \
Source/CommonFramework/Tools/StatsTracking.cpp \
Source/CommonFramework/Tools/SuperControlSession.cpp \
Source/CommonFramework/Tools/VideoResolutionCheck.cpp \
Source/CommonFramework/Tools/VideoStream.cpp \
Source/CommonFramework/VideoPipeline/Backends/CameraImplementations.cpp \
Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt5.cpp \
Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.cpp \
Expand Down Expand Up @@ -1388,6 +1389,7 @@ HEADERS += \
Source/CommonFramework/Tools/StatsTracking.h \
Source/CommonFramework/Tools/SuperControlSession.h \
Source/CommonFramework/Tools/VideoResolutionCheck.h \
Source/CommonFramework/Tools/VideoStream.h \
Source/CommonFramework/VideoPipeline/Backends/CameraImplementations.h \
Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt5.h \
Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.h \
Expand Down
149 changes: 85 additions & 64 deletions SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
#include "Common/Cpp/PrettyPrint.h"
#include "Common/Cpp/Json/JsonArray.h"
#include "Common/Cpp/Json/JsonObject.h"
#include "Common/Cpp/Concurrency/AsyncDispatcher.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/GlobalServices.h"
#include "CommonFramework/Logging/Logger.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonFramework/Environment/Environment.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "CommonFramework/Tools/ConsoleHandle.h"
#include "CommonFramework/Recording/StreamHistorySession.h"
#include "ProgramDumper.h"
#include "ErrorReports.h"

Expand Down Expand Up @@ -112,7 +114,7 @@ SendableErrorReport::SendableErrorReport(
std::string title,
std::vector<std::pair<std::string, std::string>> messages,
const ImageViewRGB32& image,
ConsoleHandle* console
const StreamHistorySession* stream_history
)
: SendableErrorReport()
{
Expand Down Expand Up @@ -145,8 +147,8 @@ SendableErrorReport::SendableErrorReport(
file.flush();
m_logs_name = ERROR_LOGS_NAME;
}
if (console){
if (console->save_stream_history(m_directory + "Video.mp4")){
if (stream_history){
if (stream_history->save(m_directory + "Video.mp4")){
m_video_name = "Video.mp4";
}
}
Expand All @@ -165,56 +167,63 @@ SendableErrorReport::SendableErrorReport(std::string directory)
JsonValue json = load_json_file(m_directory + "Report.json");
const JsonObject& obj = json.to_object_throw();
m_timestamp = obj.get_string_throw("Timestamp");
m_processor = obj.get_string_throw("Processor");
m_program = obj.get_string_throw("Program");
m_program_id = obj.get_string_throw("ProgramID");
m_program_runtime_millis = obj.get_integer_throw("ElapsedTimeMillis");
m_title = obj.get_string_throw("Title");
{
const JsonArray& messages = obj.get_array_throw("Messages");
for (const JsonValue& message : messages){
const JsonArray& item = message.to_array_throw();
if (item.size() != 2){
throw ParseException("Expected 2 values for message.");

// If we error from this point on, we'll just move it to the sent folder.
try{
m_processor = obj.get_string_throw("Processor");
m_program = obj.get_string_throw("Program");
m_program_id = obj.get_string_throw("ProgramID");
m_program_runtime_millis = obj.get_integer_throw("ElapsedTimeMillis");
m_title = obj.get_string_throw("Title");
{
const JsonArray& messages = obj.get_array_throw("Messages");
for (const JsonValue& message : messages){
const JsonArray& item = message.to_array_throw();
if (item.size() != 2){
throw ParseException("Expected 2 values for message.");
}
m_messages.emplace_back(
item[0].to_string_throw(),
item[1].to_string_throw()
);
}
m_messages.emplace_back(
item[0].to_string_throw(),
item[1].to_string_throw()
);
}
}
{
const std::string* image_name = obj.get_string("Screenshot");
if (image_name){
try{
m_image_owner = ImageRGB32(m_directory + *image_name);
m_image = m_image_owner;
}catch (FileException&){}
{
const std::string* image_name = obj.get_string("Screenshot");
if (image_name){
try{
m_image_owner = ImageRGB32(m_directory + *image_name);
m_image = m_image_owner;
}catch (FileException&){}
}
}
}
{
const std::string* video_name = obj.get_string("Video");
if (video_name){
m_video_name = *video_name;
{
const std::string* video_name = obj.get_string("Video");
if (video_name){
m_video_name = *video_name;
}
}
}
{
const std::string* dump_name = obj.get_string("Dump");
if (dump_name){
m_dump_name = *dump_name;
{
const std::string* dump_name = obj.get_string("Dump");
if (dump_name){
m_dump_name = *dump_name;
}
}
}
{
const std::string* logs_name = obj.get_string("Logs");
if (logs_name){
m_logs_name = *logs_name;
{
const std::string* logs_name = obj.get_string("Logs");
if (logs_name){
m_logs_name = *logs_name;
}
}
}
{
const JsonArray& files = obj.get_array_throw("Files");
for (const JsonValue& file : files){
m_files.emplace_back(file.to_string_throw());
{
const JsonArray& files = obj.get_array_throw("Files");
for (const JsonValue& file : files){
m_files.emplace_back(file.to_string_throw());
}
}
}catch (...){
move_to_sent();
throw;
}
}
void SendableErrorReport::add_file(std::string filename){
Expand Down Expand Up @@ -270,23 +279,22 @@ void SendableErrorReport::save(Logger* logger) const{
report.dump(m_directory + "Report.json");
}

#ifndef PA_OFFICIAL
bool SendableErrorReport::send(Logger& logger){
return false;
}
#endif

void SendableErrorReport::move_to_sent(){
// cout << "move_to_sent()" << endl;
QDir().mkdir(QString::fromStdString(ERROR_PATH_SENT));

std::string new_directory = ERROR_PATH_SENT + "/" + m_timestamp + "/";
// cout << "old: " << m_directory << endl;
// cout << "new: " << new_directory << endl;
QDir().rename(
bool success = QDir().rename(
QString::fromStdString(m_directory),
QString::fromStdString(new_directory)
);
if (success){
global_logger_tagged().log("Moved error report " + m_timestamp + ".");
}else{
global_logger_tagged().log("Unable to move error report " + m_timestamp + ".", COLOR_RED);
}
m_directory = std::move(new_directory);
}

Expand All @@ -306,37 +314,46 @@ std::vector<std::string> SendableErrorReport::get_pending_reports(){
return ret;
}

#ifndef PA_OFFICIAL
void SendableErrorReport::send(Logger& logger, std::shared_ptr<SendableErrorReport> report){}
#endif



// Send all the reports. This function will return early and all the reports
// will be sent asynchronously in the background.
void send_reports(Logger& logger, const std::vector<std::string>& reports){
for (const std::string& path : reports){
try{
SendableErrorReport report(path);
report.send(logger);
// static int c = 0;
// cout << "Sending... " << c++ << endl;
// std:::shared_ptr because it needs to take ownership for
// destruction at a later time.
SendableErrorReport::send(logger, std::make_shared<SendableErrorReport>(path));
}catch (Exception& e){
logger.log("Unable to send report: " + path + ", Message: " + e.to_str(), COLOR_RED);
}catch (...){
logger.log("Unable to send report: " + path, COLOR_RED);
}
}
}
void send_all_unsent_reports(Logger& logger, bool allow_prompt){
std::unique_ptr<AsyncTask> send_all_unsent_reports(Logger& logger, bool allow_prompt){
#ifdef PA_OFFICIAL
ErrorReportSendMode mode = GlobalSettings::instance().ERROR_REPORTS->SEND_MODE;
if (mode == ErrorReportSendMode::NEVER_SEND_ANYTHING){
return;
return nullptr;
}

std::vector<std::string> reports = SendableErrorReport::get_pending_reports();
global_logger_tagged().log("Found " + std::to_string(reports.size()) + " unsent error reports.", COLOR_PURPLE);

if (reports.empty()){
return;
return nullptr;
}

if (mode == ErrorReportSendMode::PROMPT_WHEN_CONVENIENT){
if (!allow_prompt){
return;
return nullptr;
}
QMessageBox box;
QMessageBox::StandardButton button = box.information(
Expand All @@ -356,13 +373,17 @@ void send_all_unsent_reports(Logger& logger, bool allow_prompt){
QMessageBox::StandardButton::Yes
);
if (button != QMessageBox::StandardButton::Yes){
return;
return nullptr;
}
}

global_logger_tagged().log("Attempting to send " + std::to_string(reports.size()) + " error reports.", COLOR_PURPLE);
send_reports(global_logger_tagged(), reports);

return global_async_dispatcher().dispatch([reports = std::move(reports)]{
send_reports(global_logger_tagged(), reports);
});
#else
return nullptr;
#endif
}

Expand All @@ -372,7 +393,7 @@ void report_error(
std::string title,
std::vector<std::pair<std::string, std::string>> messages,
const ImageViewRGB32& image,
ConsoleHandle* console,
const StreamHistorySession* stream_history,
const std::vector<std::string>& files
){
if (logger == nullptr){
Expand All @@ -386,7 +407,7 @@ void report_error(
std::move(title),
std::move(messages),
image,
console
stream_history
);

std::vector<std::string> full_file_paths;
Expand Down
Loading

0 comments on commit e41ed96

Please sign in to comment.