Skip to content

Commit f1ab114

Browse files
committed
Merge branch 'fixes' into lua_api
2 parents 42f7e53 + 43d65b9 commit f1ab114

19 files changed

Lines changed: 135 additions & 108 deletions

libaegisub/common/vfr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Framerate::Framerate(double fps)
143143
Framerate::Framerate(int64_t numerator, int64_t denominator, bool drop)
144144
: denominator(denominator)
145145
, numerator(numerator)
146-
, drop(drop && numerator % denominator != 0)
146+
, drop(drop && denominator != 0 && numerator % denominator != 0)
147147
{
148148
if (numerator <= 0 || denominator <= 0)
149149
throw InvalidFramerate("Numerator and denominator must both be greater than zero");
@@ -225,7 +225,7 @@ int Framerate::FrameAtTime(int ms, Time type) const {
225225
return int((ms * numerator / denominator - 999) / 1000);
226226

227227
if (ms > timecodes.back())
228-
return int((ms * numerator - last + denominator - 1) / denominator / 1000) + (int)timecodes.size() - 1;
228+
return int((ms * numerator - numerator / 2 - last + numerator - 1) / denominator / 1000) + (int)timecodes.size() - 1;
229229

230230
return (int)distance(lower_bound(timecodes.rbegin(), timecodes.rend(), ms, std::greater<int>()), timecodes.rend()) - 1;
231231
}

libaegisub/unix/util.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,13 @@
1515
#include <libaegisub/util.h>
1616

1717
#include <cstddef>
18-
19-
#ifdef _LIBCPP_VERSION
2018
#include <thread>
21-
#else
22-
#include <boost/thread.hpp>
23-
#endif
2419

2520
namespace agi { namespace util {
2621
void SetThreadName(const char *) { }
2722

2823
void sleep_for(int ms) {
29-
#ifdef __clang__
3024
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
31-
#else
32-
boost::this_thread::sleep_for(boost::chrono::milliseconds(ms));
33-
#endif
3425
}
3526

3627
} }

libaegisub/windows/fs.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ namespace bfs = boost::filesystem;
3535

3636
namespace agi { namespace fs {
3737
std::string ShortName(path const& p) {
38-
std::wstring out(MAX_PATH + 1, 0);
38+
DWORD length = GetShortPathName(p.c_str(), NULL, 0);
39+
if (!length)
40+
return p.string();
41+
42+
std::wstring out(length, 0);
3943
DWORD len = GetShortPathName(p.c_str(), &out[0], out.size());
4044
if (!len)
4145
return p.string();
@@ -60,9 +64,7 @@ void Touch(path const& file) {
6064
}
6165

6266
void Copy(fs::path const& from, fs::path const& to) {
63-
acs::CheckFileRead(from);
6467
CreateDirectory(to.parent_path());
65-
acs::CheckDirWrite(to.parent_path());
6668

6769
if (!CopyFile(from.wstring().c_str(), to.wstring().c_str(), false)) {
6870
switch (GetLastError()) {

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
project('Aegisub', ['c', 'cpp'],
22
license: 'BSD-3-Clause',
3-
meson_version: '>=0.56.1',
3+
meson_version: '>=0.57.0',
44
default_options: ['cpp_std=c++14', 'buildtype=debugoptimized'],
55
version: '3.2.2')
66

src/audio_timing_dialogue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ class AudioTimingControllerDialogue final : public AudioTimingController {
324324
/// The owning project context
325325
agi::Context *context;
326326

327-
/// The time which was clicked on for alt-dragging mode
328-
int clicked_ms;
327+
/// The time which was clicked on for alt-dragging mode, or INT_MIN if not in alt-draging mode
328+
int clicked_ms = INT_MIN;
329329

330330
/// Autocommit option
331331
const agi::OptionValue *auto_commit = OPT_GET("Audio/Auto/Commit");

src/auto4_base.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,6 @@ namespace Automation4 {
222222
});
223223
}
224224

225-
int ProgressSink::ShowDialog(wxDialog *dialog)
226-
{
227-
int ret = 0;
228-
agi::dispatch::Main().Sync([&] { ret = dialog->ShowModal(); });
229-
return ret;
230-
}
231-
232225
BackgroundScriptRunner::BackgroundScriptRunner(wxWindow *parent, std::string const& title)
233226
: impl(new DialogProgress(parent, to_wx(title)))
234227
{
@@ -323,7 +316,8 @@ namespace Automation4 {
323316

324317
std::vector<std::future<std::unique_ptr<Script>>> script_futures;
325318

326-
for (auto tok : agi::Split(path, '|')) {
319+
auto path_it = agi::Split(path, '|');
320+
for (auto tok : std::set<agi::StringRange>(begin(path_it), end(path_it))) {
327321
auto dirname = config::path->Decode(agi::str(tok));
328322
if (!agi::fs::DirectoryExists(dirname)) continue;
329323

src/auto4_base.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ namespace Automation4 {
132132
/// Show the passed dialog on the GUI thread, blocking the calling
133133
/// thread until it closes
134134
void ShowDialog(ScriptDialog *config_dialog);
135-
int ShowDialog(wxDialog *dialog);
136135
wxWindow *GetParentWindow() const { return bsr->GetParentWindow(); }
137136

138137
/// Get the current automation trace level

src/auto4_lua.cpp

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ namespace {
127127

128128
const char *clipboard_get()
129129
{
130-
std::string data = GetClipboard();
130+
std::string data;
131+
agi::dispatch::Main().Sync([&] { data = GetClipboard(); });
131132
if (data.empty())
132133
return nullptr;
133134
return strndup(data);
@@ -137,18 +138,14 @@ namespace {
137138
{
138139
bool succeeded = false;
139140

140-
#if wxUSE_OLE
141-
// OLE needs to be initialized on each thread that wants to write to
142-
// the clipboard, which wx does not handle automatically
143-
wxClipboard cb;
144-
#else
145-
wxClipboard &cb = *wxTheClipboard;
146-
#endif
147-
if (cb.Open()) {
148-
succeeded = cb.SetData(new wxTextDataObject(wxString::FromUTF8(str)));
149-
cb.Close();
150-
cb.Flush();
151-
}
141+
agi::dispatch::Main().Sync([&] {
142+
wxClipboard &cb = *wxTheClipboard;
143+
if (cb.Open()) {
144+
succeeded = cb.SetData(new wxTextDataObject(wxString::FromUTF8(str)));
145+
cb.Close();
146+
cb.Flush();
147+
}
148+
});
152149

153150
return succeeded;
154151
}
@@ -785,27 +782,33 @@ namespace {
785782
{
786783
bool failed = false;
787784
BackgroundScriptRunner bsr(parent, title);
788-
bsr.Run([&](ProgressSink *ps) {
789-
LuaProgressSink lps(L, ps, can_open_config);
790-
791-
// Insert our error handler under the function to call
792-
lua_pushcclosure(L, add_stack_trace, 0);
793-
lua_insert(L, -nargs - 2);
794-
795-
if (lua_pcall(L, nargs, nresults, -nargs - 2)) {
796-
if (!lua_isnil(L, -1)) {
797-
// if the call failed, log the error here
798-
ps->Log("\n\nLua reported a runtime error:\n");
799-
ps->Log(get_string_or_default(L, -1));
785+
try {
786+
bsr.Run([&](ProgressSink *ps) {
787+
LuaProgressSink lps(L, ps, can_open_config);
788+
789+
// Insert our error handler under the function to call
790+
lua_pushcclosure(L, add_stack_trace, 0);
791+
lua_insert(L, -nargs - 2);
792+
793+
if (lua_pcall(L, nargs, nresults, -nargs - 2)) {
794+
if (!lua_isnil(L, -1)) {
795+
// if the call failed, log the error here
796+
ps->Log("\n\nLua reported a runtime error:\n");
797+
ps->Log(get_string_or_default(L, -1));
798+
}
799+
lua_pop(L, 2);
800+
failed = true;
800801
}
801-
lua_pop(L, 2);
802-
failed = true;
803-
}
804-
else
805-
lua_remove(L, -nresults - 1);
802+
else
803+
lua_remove(L, -nresults - 1);
806804

807-
lua_gc(L, LUA_GCCOLLECT, 0);
808-
});
805+
lua_gc(L, LUA_GCCOLLECT, 0);
806+
});
807+
} catch (agi::UserCancelException const&) {
808+
if (!failed)
809+
lua_pop(L, 2);
810+
throw;
811+
}
809812
if (failed)
810813
throw agi::UserCancelException("Script threw an error");
811814
}

src/auto4_lua_dialog.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ namespace Automation4 {
284284
max = DBL_MAX;
285285
min = -DBL_MAX;
286286
}
287+
if (step != 0.0) {
288+
min = min == -DBL_MAX ? 0.0 : min;
289+
max = max == DBL_MAX ? 100.0 : max;
290+
}
287291
}
288292

289293
bool CanSerialiseValue() const override { return true; }

src/auto4_lua_progresssink.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include "compat.h"
3838

39+
#include <libaegisub/dispatch.h>
3940
#include <libaegisub/lua/utils.h>
4041

4142
#include <wx/filedlg.h>
@@ -197,7 +198,6 @@ namespace Automation4 {
197198

198199
int LuaProgressSink::LuaDisplayOpenDialog(lua_State *L)
199200
{
200-
ProgressSink *ps = GetObjPointer(L, lua_upvalueindex(1));
201201
wxString message(check_wxstring(L, 1));
202202
wxString dir(check_wxstring(L, 2));
203203
wxString file(check_wxstring(L, 3));
@@ -211,26 +211,24 @@ namespace Automation4 {
211211
if (must_exist)
212212
flags |= wxFD_FILE_MUST_EXIST;
213213

214-
wxFileDialog diag(nullptr, message, dir, file, wildcard, flags);
215-
if (ps->ShowDialog(&diag) == wxID_CANCEL) {
216-
lua_pushnil(L);
217-
return 1;
218-
}
219-
220-
if (multiple) {
221-
wxArrayString files;
222-
diag.GetPaths(files);
223-
224-
lua_createtable(L, files.size(), 0);
225-
for (size_t i = 0; i < files.size(); ++i) {
226-
lua_pushstring(L, files[i].utf8_str());
227-
lua_rawseti(L, -2, i + 1);
214+
agi::dispatch::Main().Sync([&] {
215+
wxFileDialog diag(nullptr, message, dir, file, wildcard, flags);
216+
if (diag.ShowModal() == wxID_CANCEL) {
217+
lua_pushnil(L);
218+
} else if (multiple) {
219+
wxArrayString files;
220+
diag.GetPaths(files);
221+
222+
lua_createtable(L, files.size(), 0);
223+
for (size_t i = 0; i < files.size(); ++i) {
224+
lua_pushstring(L, files[i].utf8_str());
225+
lua_rawseti(L, -2, i + 1);
226+
}
227+
} else {
228+
lua_pushstring(L, diag.GetPath().utf8_str());
228229
}
230+
});
229231

230-
return 1;
231-
}
232-
233-
lua_pushstring(L, diag.GetPath().utf8_str());
234232
return 1;
235233
}
236234

@@ -247,13 +245,15 @@ namespace Automation4 {
247245
if (prompt_overwrite)
248246
flags |= wxFD_OVERWRITE_PROMPT;
249247

250-
wxFileDialog diag(ps->GetParentWindow(), message, dir, file, wildcard, flags);
251-
if (ps->ShowDialog(&diag) == wxID_CANCEL) {
252-
lua_pushnil(L);
253-
return 1;
254-
}
248+
agi::dispatch::Main().Sync([&] {
249+
wxFileDialog diag(ps->GetParentWindow(), message, dir, file, wildcard, flags);
250+
if (diag.ShowModal() == wxID_CANCEL) {
251+
lua_pushnil(L);
252+
} else {
253+
lua_pushstring(L, diag.GetPath().utf8_str());
254+
}
255+
});
255256

256-
lua_pushstring(L, diag.GetPath().utf8_str());
257257
return 1;
258258
}
259259
}

0 commit comments

Comments
 (0)