22#include <wx/filename.h>
52 mLogFile.Open(logFile.GetFullPath(wxPATH_NATIVE), L
"w");
56 mLogFile.Write(
str.data(),
str.size());
77 return str.ToStdString();
83 return std::to_string(arg);
86template<
typename... Args>
87void Log( std::string_view message,
const Args&... args )
92 constexpr auto n =
sizeof...(Args);
94 std::string strings[n];
96 ((strings[i++] =
ToString(args)), ...);
101 while (!message.empty())
103 const auto placeholderPos = message.find(
"{}");
107 logger.WriteString(message);
111 std::string_view arg = strings[i++];
113 logger.WriteString(message.substr(0, placeholderPos));
114 logger.WriteString(arg);
116 message = message.substr(placeholderPos + 2);
119 logger.FinalizeMessge();
141 if ( tokens.empty() )
161 auto str = wxString::Format(
"%d", number );
162 result += ( result.empty() ?
str : (
'.' +
str ) );
170 auto strings = wxSplit( value,
'.' );
171 std::vector<int> numbers;
172 for (
auto &
string : strings ) {
174 if ( !
string.ToCLong( &value ) )
176 numbers.push_back( value );
180 return !std::lexicographical_compare(
182 numbers.begin(), numbers.end() );
192 Log(
"Journal sync failed: {}",
string);
200 wxCommandEvent evt{ wxEVT_MENU, wxID_EXIT };
201 wxTheApp->AddPendingEvent( evt );
230 fName.MakeAbsolute( dataDir );
231 const auto path = fName.GetFullPath();
235 Log(
"Journal: failed to open journal file \"{}\"", path);
245 if (!(tokens.size() == 2 && tokens[0] ==
VersionToken &&
248 Log(
"Journal: invalid journal version: \"{}\"", tokens[1]);
255 wxFileName fName{ dataDir,
"journal",
"txt" };
256 const auto path = fName.GetFullPath();
262 wxT(
"Journal recorded by %s on %s")
264 , wxDateTime::Now().
Format()
284 if ( !result.empty() ) {
307 auto &
name = words[0];
308 auto iter = table.find(
name );
309 if (iter == table.end())
311 wxString::Format(
"unknown command: %s",
name.ToStdString().c_str()));
314 if (!iter->second(words))
316 "command '%s' has failed", wxJoin(words,
',').ToStdString().c_str()));
321void Sync(
const wxString &
string )
330 "sync failed. Expected '%s', got '%s'",
331 string.ToStdString().c_str(),
sLine.ToStdString().c_str()));
339void Sync(
const wxArrayString &strings )
347void Sync( std::initializer_list< const wxString > strings )
361 if ( tokens.size() == 1 ) {
363 std::wstring
str{ tokens[0].wc_str() };
365 auto result = std::stoi(
str, &length);
366 if (length ==
str.length()) {
372 catch (
const std::exception& ) {}
376 "unexpected tokens: %s", wxJoin(tokens,
',').ToStdString().c_str()));
379 auto result = action ? action() : 0;
381 Output( std::to_wstring( result ) );
The output stream of the journal system.
Journal system's error status, command dictionary, initializers.
audacity::BasicSettings * gPrefs
This specialization of Setting for bool adds a Toggle method to negate the saved value.
SyncException(const wxString &message)
Constructs an exception with a message; message is logged into the journallog.txt file.
~SyncException() override
void DelayedHandlerAction() override
Action to do in the main thread at idle time of the event loop.
void WriteString(std::string_view str)
bool Write(const T &value)
Write value to config and return true if successful.
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined */
virtual bool Flush() noexcept=0
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
FILES_API FilePath DataDir()
Audacity user data directory.
RegisteredInitializer initializer
std::string ToString(const T &arg)
constexpr auto VersionToken
int journalVersionNumbers[]
JournalLogger & GetLogger()
void Log(std::string_view message, const Args &... args)
wxArrayStringEx PeekTokens()
BoolSetting JournalEnabled
bool VersionCheck(const wxString &value)
True if value is an acceptable journal version number to be rerun.
Facilities for recording and playback of sequences of user interaction.
bool Begin(const FilePath &dataDir)
void SetInputFileName(const wxString &path)
void Sync(const wxString &string)
const Dictionary & GetDictionary()
bool SetRecordEnabled(bool value)
void Comment(const wxString &string)
const Initializers & GetInitializers()
constexpr auto EscapeCharacter
wxArrayStringEx GetTokens()
int IfNotPlaying(const wxString &string, const InteractiveAction &action)
Call action only if not replaying; synchronize on string and int values.
void Output(const wxString &string)
constexpr auto SeparatorCharacter
std::function< int() > InteractiveAction
Function that returns a value which will be written to the journal.
constexpr auto CommentCharacter
bool OpenOut(const wxString &fullPath)
constexpr size_t npos(-1)
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept