├── src ├── precomp.cpp ├── Ets2 │ ├── precomp.hpp │ ├── Parser │ │ ├── precomp.hpp │ │ ├── SiiText.hpp │ │ ├── Cfg.hpp │ │ ├── Sii.hpp │ │ ├── Cfg.rl │ │ ├── SiiText.rl.cpp │ │ ├── Cfg.rl.cpp │ │ ├── SiiBinary.hpp │ │ └── SiiText.rl │ ├── lib │ │ ├── precomp.hpp │ │ ├── Utf8ToUtf16.hpp │ │ ├── file.hpp │ │ ├── Utf8ToUtf16.cpp │ │ └── file.cpp │ ├── File.cpp │ ├── Info.cpp │ ├── Save.cpp │ ├── Profile.cpp │ ├── ObjectList.hpp │ ├── Profile.hpp │ ├── Save.hpp │ ├── Info.hpp │ ├── Object.hpp │ ├── Object.cpp │ └── File.hpp ├── JobSyncer.cpp ├── MainWindow.cpp ├── SyncDialog.cpp ├── ObjectCombobox.hpp ├── UpdateChecker.cpp ├── GameSettingsPanel.cpp ├── Ets2SyncHelperApp.hpp ├── SaveSelector.hpp ├── ShowLastWindowsError.hpp ├── ProfileSelector.hpp ├── StatusText.hpp ├── JobListSelector.hpp ├── Ets2StaticBox.hpp ├── DlcSelector.hpp ├── precomp.hpp ├── Ets2SyncHelperApp.cpp ├── SyncDialog.hpp ├── AboutWindow.hpp ├── version.hpp ├── ProfileSelector.cpp ├── SaveSelector.cpp ├── StatusText.cpp ├── Ets2StaticBox.cpp ├── JobListSelector.cpp ├── UpdateChecker.hpp ├── JobSyncer.hpp ├── MainWindow.hpp ├── GameSettingsPanel.hpp ├── ObjectSelector.hpp ├── ShowLastWindowsError.cpp ├── DlcSelector.cpp └── AboutWindow.cpp ├── res ├── app.rc ├── app.ico ├── icon_256.png └── resource.h ├── .gitattributes ├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── LICENSE.md ├── ETS2Sync-Helper.sln ├── lib └── rapidjson │ ├── internal │ ├── swap.h │ ├── strfunc.h │ ├── ieee754.h │ ├── pow10.h │ ├── meta.h │ ├── stack.h │ ├── dtoa.h │ ├── strtod.h │ └── biginteger.h │ ├── cursorstreamwrapper.h │ ├── ostreamwrapper.h │ ├── memorybuffer.h │ ├── memorystream.h │ ├── filereadstream.h │ ├── filewritestream.h │ ├── error │ ├── en.h │ └── error.h │ ├── istreamwrapper.h │ ├── stringbuffer.h │ ├── fwd.h │ ├── stream.h │ └── msinttypes │ ├── inttypes.h │ └── stdint.h ├── README-fr.md ├── .gitignore ├── README.md └── ETS2Sync-Helper-4.vcxproj.filters /src/precomp.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" -------------------------------------------------------------------------------- /src/Ets2/precomp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../precomp.hpp" -------------------------------------------------------------------------------- /src/Ets2/Parser/precomp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../precomp.hpp" 3 | -------------------------------------------------------------------------------- /src/Ets2/lib/precomp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../precomp.hpp" 3 | -------------------------------------------------------------------------------- /res/app.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/res/app.rc -------------------------------------------------------------------------------- /res/app.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/res/app.ico -------------------------------------------------------------------------------- /res/icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/res/icon_256.png -------------------------------------------------------------------------------- /src/Ets2/File.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/src/Ets2/File.cpp -------------------------------------------------------------------------------- /src/Ets2/Info.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/src/Ets2/Info.cpp -------------------------------------------------------------------------------- /src/Ets2/Save.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/src/Ets2/Save.cpp -------------------------------------------------------------------------------- /src/JobSyncer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/src/JobSyncer.cpp -------------------------------------------------------------------------------- /src/Ets2/Profile.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/src/Ets2/Profile.cpp -------------------------------------------------------------------------------- /src/MainWindow.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/src/MainWindow.cpp -------------------------------------------------------------------------------- /src/SyncDialog.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/src/SyncDialog.cpp -------------------------------------------------------------------------------- /src/ObjectCombobox.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/src/ObjectCombobox.hpp -------------------------------------------------------------------------------- /src/UpdateChecker.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/src/UpdateChecker.cpp -------------------------------------------------------------------------------- /src/GameSettingsPanel.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inklay/ETS2-ATS-Sync-Helper/HEAD/src/GameSettingsPanel.cpp -------------------------------------------------------------------------------- /src/Ets2/lib/Utf8ToUtf16.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | void Utf8ToUtf16(const char * src, size_t srcLength, std::wstring& dst); 5 | -------------------------------------------------------------------------------- /src/Ets2/lib/file.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | void read_file(const std::wstring& filename, std::string& contents); 6 | void write_file(const std::string& contents, const std::wstring& filename); -------------------------------------------------------------------------------- /src/Ets2SyncHelperApp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Ets2SyncHelperApp : public wxApp { 4 | public: 5 | virtual bool OnInit(); 6 | virtual int OnExit(); 7 | 8 | private: 9 | wxLocale * mLocale; 10 | }; 11 | -------------------------------------------------------------------------------- /src/Ets2/Parser/SiiText.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Sii.hpp" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Ets2::Parser::Sii { 9 | class Text { 10 | public: 11 | static bool parse(const std::string& data, const ParseCallback& callback); 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /src/SaveSelector.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ObjectSelector.hpp" 4 | 5 | wxDECLARE_EVENT(EVT_SAVE_SELECTED, wxCommandEvent); 6 | 7 | typedef ObjectSelector SaveSelector; 8 | 9 | template <> const Ets2::SaveList * SaveSelector::getList(); 10 | template <> void SaveSelector::onObjectChanged(); 11 | -------------------------------------------------------------------------------- /src/ShowLastWindowsError.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Gets the message for the error returned by GetLastError(), formats it, and shows it with wxLogError 4 | // task: Indicator of what function call or task failed (usually the name of the Windows API function that was called) 5 | void ShowLastWindowsError(const wchar_t * task); 6 | -------------------------------------------------------------------------------- /src/ProfileSelector.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ObjectSelector.hpp" 4 | 5 | typedef ObjectSelector ProfileSelector; 6 | 7 | wxDECLARE_EVENT(EVT_PROFILE_SELECTED, wxCommandEvent); 8 | 9 | template <> const Ets2::ProfileList * ProfileSelector::getList(); 10 | template <> void ProfileSelector::onObjectChanged(); 11 | -------------------------------------------------------------------------------- /src/Ets2/ObjectList.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Ets2 { 4 | template class ObjectList : public std::vector { 5 | public: 6 | ~ObjectList() { 7 | for (auto item : *this) { 8 | delete item; 9 | } 10 | } 11 | 12 | void ObjectList::sort() { 13 | std::sort(begin(), end(), &(T::compareForSort)); 14 | } 15 | }; 16 | } -------------------------------------------------------------------------------- /src/StatusText.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class StatusText : public wxStaticText { 4 | public: 5 | StatusText(wxWindow * wwParent, wxWindowID id); 6 | enum class Type { 7 | STATUS, 8 | SUCCESS, 9 | WARNING, 10 | FAILURE 11 | }; 12 | Type getType() const; 13 | void SetLabel(const wxString& wsLabel, Type newType); 14 | 15 | private: 16 | Type mType; 17 | }; -------------------------------------------------------------------------------- /src/Ets2/Parser/Cfg.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Ets2::Parser { 7 | class Cfg { 8 | public: 9 | typedef const std::function& CALLBACK_FUNC; 10 | 11 | static void parse(const std::string& data, CALLBACK_FUNC callback); 12 | }; 13 | } -------------------------------------------------------------------------------- /src/JobListSelector.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Ets2StaticBox.hpp" 4 | 5 | class JobListSelector : public Ets2StaticBox { 6 | public: 7 | JobListSelector(wxWindow * parent, wxWindowID id); 8 | 9 | int getJobList() const; 10 | void setJobList(int jobList); 11 | 12 | private: 13 | wxChoice * mJobList; 14 | wxStaticText * mAutoListInfo; 15 | 16 | void onSetJobList(); 17 | }; -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /src/Ets2StaticBox.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Ets2/Info.hpp" 4 | 5 | class Ets2StaticBox : public wxStaticBox { 6 | public: 7 | Ets2StaticBox(wxWindow * parent, wxWindowID id, wxString label); 8 | 9 | void setEts2Info(Ets2::Info * ets2Info); 10 | Ets2::Info * getEts2Info(); 11 | wxBoxSizer * getContentSizer(); 12 | 13 | protected: 14 | virtual void updateFromEts2Info(); 15 | 16 | private: 17 | Ets2::Info * mEts2Info; 18 | wxBoxSizer * mContentSizer; 19 | }; -------------------------------------------------------------------------------- /src/Ets2/Parser/Sii.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Ets2::Parser::Sii { 8 | enum class Context { 9 | UNIT_START, 10 | ATTRIBUTE, 11 | UNIT_END 12 | }; 13 | 14 | typedef std::function ParseCallback; 16 | } 17 | 18 | #include "SiiText.hpp" 19 | #include "SiiBinary.hpp" -------------------------------------------------------------------------------- /res/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by app.rc 4 | // 5 | 6 | // Next default values for new objects 7 | // 8 | #ifdef APSTUDIO_INVOKED 9 | #ifndef APSTUDIO_READONLY_SYMBOLS 10 | #define _APS_NO_MFC 1 11 | #define _APS_NEXT_RESOURCE_VALUE 101 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1000 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Setup information** 21 | - The game you're playing on (either ATS or ETS2) 22 | - The game version 23 | - The app version 24 | - The DLCs you have 25 | -------------------------------------------------------------------------------- /src/DlcSelector.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Ets2StaticBox.hpp" 4 | 5 | #include 6 | 7 | class DlcSelector : public Ets2StaticBox { 8 | public: 9 | DlcSelector(wxWindow * parent, wxWindowID); 10 | 11 | void setSave(const Ets2::Save * save); 12 | const Ets2::Save::DlcList getDlcs() const; 13 | 14 | private: 15 | wxHyperlinkCtrl * mSelectAll; 16 | 17 | std::map> mCheckboxesByGame; 18 | std::map mDlcByCheckbox; 19 | const Ets2::Save * mSave; 20 | 21 | void onSelectAll(); 22 | }; -------------------------------------------------------------------------------- /src/precomp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #define DEBUG_CLASS_NAME [this]() { \ 10 | wxString __s = wxString(typeid(*this).name()); \ 11 | if (__s.Find("class ") != wxNOT_FOUND) { \ 12 | __s.Replace(L"class ", L""); \ 13 | } \ 14 | return __s; \ 15 | }() 16 | #define DEBUG_LOG(fmt, ...) wxLogDebug(wxString(L"%s::%s: ") + wxString(fmt), DEBUG_CLASS_NAME, __func__, __VA_ARGS__) 17 | #define DEBUG_LOG_LINE(fmt, ...) wxLogDebug(wxString(L"%s:%d at %s::%s: ") + wxString(fmt), wxString(__FILE__).AfterLast(L'\\'), __LINE__, DEBUG_CLASS_NAME, __func__, __VA_ARGS__) 18 | -------------------------------------------------------------------------------- /src/Ets2SyncHelperApp.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "Ets2SyncHelperApp.hpp" 3 | #include "version.hpp" 4 | #include "MainWindow.hpp" 5 | 6 | wxIMPLEMENT_APP(Ets2SyncHelperApp); 7 | 8 | bool Ets2SyncHelperApp::OnInit() { 9 | mLocale = new wxLocale(wxLANGUAGE_DEFAULT); 10 | 11 | wxApp::OnInit(); 12 | 13 | SetAppName(APP_NAME); 14 | SetAppDisplayName(APP_DISPLAY_NAME); 15 | wxInitAllImageHandlers(); 16 | 17 | MainWindow *mainWindow = new MainWindow(APP_DISPLAY_NAME + " " + APP_VERSION); 18 | SetTopWindow(mainWindow); 19 | mainWindow->Show(true); 20 | 21 | return true; 22 | } 23 | 24 | int Ets2SyncHelperApp::OnExit() { 25 | delete mLocale; 26 | return wxApp::OnExit(); 27 | } 28 | -------------------------------------------------------------------------------- /src/SyncDialog.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Ets2/Save.hpp" 4 | #include "StatusText.hpp" 5 | #include "JobSyncer.hpp" 6 | 7 | class SyncDialog : public wxDialog { 8 | public: 9 | SyncDialog(wxWindow * parent, const Ets2::Save * save, const Ets2::Save::DlcList& dlcs, JobSyncer::SyncType syncType, int jobList); 10 | ~SyncDialog(); 11 | 12 | private: 13 | wxWindow * mParent; 14 | const Ets2::Save * mSave; 15 | std::vector mDlcs; 16 | JobSyncer::SyncType mSyncType; 17 | int mJobList; 18 | StatusText * mStatus; 19 | wxStaticText * mSubStatus; 20 | wxGauge * mProgressBar; 21 | wxButton * mCloseButton; 22 | JobSyncer * mJobSyncer; 23 | 24 | void onClose(); 25 | void onJobSyncerUpdate(); 26 | }; -------------------------------------------------------------------------------- /src/AboutWindow.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "UpdateChecker.hpp" 4 | #include "StatusText.hpp" 5 | 6 | #include 7 | 8 | // About Window 9 | class AboutWindow : public wxDialog { 10 | public: 11 | AboutWindow(class MainWindow * wndParent); 12 | ~AboutWindow(); 13 | 14 | MainWindow * GetParent(); 15 | private: 16 | UpdateChecker * mUpdateChecker; 17 | wxActivityIndicator * mCheckingAnimation; 18 | StatusText * mCheckStatusText; 19 | wxBoxSizer * mUpdateCheckSizer; 20 | wxButton * mUpdateCheckAgain; 21 | 22 | void onShow(wxShowEvent& event); 23 | void onOpenWebsite(); 24 | void onUpdateCheckAgain(); 25 | void onClose(); 26 | void onUpdateStatus(); 27 | 28 | void checkUpdates(); 29 | }; -------------------------------------------------------------------------------- /src/version.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define THIS_APP_VERSION L"5.9.0" 6 | 7 | const std::wstring APP_NAME = L"ETS2-ATS-Sync-Helper"; 8 | const std::wstring APP_DISPLAY_NAME = L"ETS2&ATS Sync Helper"; 9 | const std::wstring APP_VERSION = THIS_APP_VERSION; 10 | 11 | const std::wstring APP_URL_WEBSITE = L"https://github.com/Inklay/"; 12 | 13 | #if _DEBUG 14 | const std::wstring APP_URL_BASE = L"http://localhost:80/SyncHelper/app/"; 15 | #else 16 | const std::wstring APP_URL_BASE = L"https://inklay.net/SyncHelper/app/"; 17 | #endif 18 | 19 | const std::wstring APP_URL_CHECK_VERSION = APP_URL_BASE + "check_version?v=" + APP_VERSION; 20 | 21 | const std::wstring APP_URL_SYNC = APP_URL_BASE + "sync?v=" + APP_VERSION; -------------------------------------------------------------------------------- /src/Ets2/lib/Utf8ToUtf16.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "Utf8ToUtf16.hpp" 3 | 4 | void Utf8ToUtf16(const char * src, size_t srcLength, std::wstring& dst) { 5 | if (srcLength == 0) { 6 | dst.clear(); 7 | return; 8 | } 9 | int len = MultiByteToWideChar(CP_UTF8, 0, src, srcLength, NULL, 0); 10 | if (len > 0) { 11 | dst.resize(len); 12 | if (MultiByteToWideChar(CP_UTF8, 0, src, srcLength, &dst[0], dst.length())) { 13 | return; 14 | } 15 | } 16 | // conversion failed; do a raw copy 17 | wxLogDebug(L"UTF8 conversion failed for string '%s'.", std::string(src, srcLength)); 18 | dst.resize(srcLength); 19 | wchar_t * dstPtr = &dst[0]; 20 | for (size_t idx = 0; idx < srcLength; idx++) { 21 | *(dstPtr + idx) = *(src + idx); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/ProfileSelector.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "ProfileSelector.hpp" 3 | 4 | wxDEFINE_EVENT(EVT_PROFILE_SELECTED, wxCommandEvent); 5 | 6 | wxString ProfileSelector::mLabel = "Select %ls Profile"; 7 | wxString ProfileSelector::mFormatZero = "No %ls profiles found."; 8 | wxString ProfileSelector::mFormatOne = "1 %ls profile."; 9 | wxString ProfileSelector::mFormatPlural = "%u %ls profiles."; 10 | 11 | template <> const Ets2::ProfileList * ProfileSelector::getList() { 12 | Ets2::Info * ets2Info = getEts2Info(); 13 | if (ets2Info->isValid()) { 14 | return &ets2Info->getProfiles(); 15 | } else { 16 | return nullptr; 17 | } 18 | } 19 | 20 | template <> void ProfileSelector::onObjectChanged() { 21 | QueueEvent(new wxCommandEvent(EVT_PROFILE_SELECTED)); 22 | }; 23 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # License 2 | All source code files (including but not limited to C++ and Ragel sources) within this repository are released under the following license: 3 | 4 | Copyright 2016 David Santos 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | -------------------------------------------------------------------------------- /src/SaveSelector.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "SaveSelector.hpp" 3 | 4 | wxDEFINE_EVENT(EVT_SAVE_SELECTED, wxCommandEvent); 5 | 6 | wxString SaveSelector::mLabel = "Select %ls Save"; 7 | wxString SaveSelector::mFormatZero = "No %ls saves found."; 8 | wxString SaveSelector::mFormatOne = "1 %ls save."; 9 | wxString SaveSelector::mFormatPlural = "%u %ls saves."; 10 | 11 | template <> const Ets2::SaveList * SaveSelector::getList() { 12 | Ets2::Info * ets2Info = getEts2Info(); 13 | if (ets2Info->isValid() && !ets2Info->getProfiles().empty()) { 14 | return &getEts2Info()->getProfiles()[0]->getSaves(); 15 | } else { 16 | return nullptr; 17 | } 18 | } 19 | 20 | template <> void SaveSelector::onObjectChanged() { 21 | QueueEvent(new wxCommandEvent(EVT_SAVE_SELECTED)); 22 | } -------------------------------------------------------------------------------- /src/Ets2/Profile.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Object.hpp" 4 | #include "Save.hpp" 5 | 6 | #include 7 | 8 | namespace Ets2 { 9 | class Profile : public Object { 10 | public: 11 | Profile(const std::wstring directory); 12 | 13 | const SaveList& getSaves() const; 14 | 15 | private: 16 | static const std::wstring SII_BASENAME; 17 | static const std::string NAME_ATTRIBUTE; 18 | static const std::string SAVE_TIME_ATTRIBUTE; 19 | static const std::string MAP_ATTRIBUTE; 20 | static const std::string MAP_VALUE_ETS2; 21 | static const std::string MAP_VALUE_ATS; 22 | 23 | SaveList mSaves; 24 | bool mMapValid; 25 | 26 | virtual void processAttribute(Parser::Sii::Context context, const std::string& name, const std::string& value) override; 27 | virtual bool validate() override; 28 | }; 29 | 30 | typedef ObjectList ProfileList; 31 | } -------------------------------------------------------------------------------- /src/Ets2/lib/file.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "file.hpp" 3 | 4 | #include 5 | #include 6 | 7 | void read_file(const std::wstring& filename, std::string& contents) { 8 | std::ifstream file(filename, std::ios::in | std::ios::binary); 9 | if (file) { 10 | file.seekg(0, std::ios::end); 11 | std::streampos size = file.tellg(); 12 | if (size > std::numeric_limits::max()) { 13 | throw std::length_error("The file is too big."); 14 | } 15 | contents.resize((size_t) size); 16 | file.seekg(0, std::ios::beg); 17 | file.read(&contents[0], contents.size()); 18 | file.close(); 19 | return; 20 | } 21 | throw(errno); 22 | } 23 | 24 | void write_file(const std::string& contents, const std::wstring& filename) { 25 | std::ofstream file(filename, std::ios::out | std::ios::binary); 26 | if (file) { 27 | file << contents; 28 | return; 29 | } 30 | throw(errno); 31 | } -------------------------------------------------------------------------------- /src/StatusText.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "StatusText.hpp" 3 | 4 | StatusText::StatusText(wxWindow * wwParent, wxWindowID id) 5 | : wxStaticText(wwParent, id, wxEmptyString) { 6 | 7 | // set font and color in case the default is different 8 | mType = Type::SUCCESS; 9 | SetLabel(wxEmptyString, Type::STATUS); 10 | } 11 | 12 | StatusText::Type StatusText::getType() const { 13 | return mType; 14 | } 15 | 16 | void StatusText::SetLabel(const wxString& wsLabel, Type newType) { 17 | if (newType != mType) { 18 | mType = newType; 19 | wxFont font = GetFont().GetBaseFont(); 20 | if (mType != Type::STATUS) 21 | font = font.MakeBold(); 22 | SetFont(font); 23 | 24 | wxColor color; 25 | switch (mType) { 26 | case Type::STATUS: 27 | color = wxColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); 28 | break; 29 | case Type::SUCCESS: 30 | color = wxColor(0x008800); 31 | break; 32 | case Type::WARNING: 33 | color = wxColor(0x22aadd); 34 | break; 35 | case Type::FAILURE: 36 | color = wxColor(0x0000ff); 37 | break; 38 | } 39 | SetForegroundColour(color); 40 | } 41 | wxStaticText::SetLabel(wsLabel); 42 | } 43 | -------------------------------------------------------------------------------- /ETS2Sync-Helper.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30413.136 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ETS2Sync-Helper", "ETS2Sync-Helper-4.vcxproj", "{C58DE3D1-9460-4ACD-A334-8A8B9991DEF4}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x86 = Debug|x86 11 | Release|x86 = Release|x86 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C58DE3D1-9460-4ACD-A334-8A8B9991DEF4}.Debug|x86.ActiveCfg = Debug|Win32 15 | {C58DE3D1-9460-4ACD-A334-8A8B9991DEF4}.Debug|x86.Build.0 = Debug|Win32 16 | {C58DE3D1-9460-4ACD-A334-8A8B9991DEF4}.Release|x86.ActiveCfg = Release|Win32 17 | {C58DE3D1-9460-4ACD-A334-8A8B9991DEF4}.Release|x86.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {C892CB13-280E-4E1C-8EF6-44339B6C0595} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /src/Ets2StaticBox.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "Ets2StaticBox.hpp" 3 | 4 | Ets2StaticBox::Ets2StaticBox(wxWindow * parent, wxWindowID id, wxString label) 5 | : wxStaticBox(parent, id, label) { 6 | mEts2Info = nullptr; 7 | 8 | wxBoxSizer * canvas = new wxBoxSizer(wxVERTICAL); 9 | 10 | wxPoint border = wxDLG_UNIT(this, wxPoint(5, 7)); 11 | wxBoxSizer * borderSizer = new wxBoxSizer(wxVERTICAL); 12 | borderSizer->AddSpacer(wxDLG_UNIT(this, wxPoint(0, 4)).y); 13 | canvas->Add(borderSizer, wxSizerFlags().Border(wxTOP | wxBOTTOM, border.y).Expand()); 14 | 15 | mContentSizer = new wxBoxSizer(wxVERTICAL); 16 | borderSizer->Add(mContentSizer, wxSizerFlags().Border(wxLEFT | wxRIGHT, border.x).Expand()); 17 | 18 | SetSizer(canvas); 19 | } 20 | 21 | Ets2::Info * Ets2StaticBox::getEts2Info() { 22 | return mEts2Info; 23 | } 24 | 25 | void Ets2StaticBox::setEts2Info(Ets2::Info * ets2Info) { 26 | mEts2Info = ets2Info; 27 | updateFromEts2Info(); 28 | } 29 | 30 | wxBoxSizer * Ets2StaticBox::getContentSizer() { 31 | return mContentSizer; 32 | } 33 | 34 | // Subclasses should reimplement this; it's called after mEts2Info changes. 35 | void Ets2StaticBox::updateFromEts2Info() { 36 | } -------------------------------------------------------------------------------- /src/Ets2/Parser/Cfg.rl: -------------------------------------------------------------------------------- 1 | %%{ 2 | machine cfgParser; 3 | 4 | action nameStart { 5 | varNameStart = p; 6 | } 7 | 8 | action nameEnd { 9 | varName.assign(varNameStart, p - varNameStart); 10 | } 11 | 12 | action valueRawStart { 13 | varValueRawStart = p; 14 | // wxLogDebug("valueRawStart"); 15 | } 16 | 17 | action valueRawEnd { 18 | varValue.append(varValueRawStart, p - varValueRawStart); 19 | // wxLogDebug("valueRawEnd (%d chars)", p - varValueRawStart); 20 | } 21 | 22 | action valueEscapedChar { 23 | varValue.push_back(*(p-1)); 24 | } 25 | 26 | action valueEscapedHex { 27 | varValue.push_back(((p[-2] & 0x40 ? 9 : 0) + (p[-2] & 0x0F)) << 4 | ((p[-1] & 0x40 ? 9 : 0) + (p[-1] & 0x0F))); 28 | } 29 | 30 | text_char = print; 31 | comment = '#' . any*; 32 | whitespace = [ \t]; 33 | varname = (alpha . (alpha | digit | '_')*) >nameStart %nameEnd; 34 | escape_hex = 'x' . xdigit{2}; 35 | escape_seq = '\\' . (escape_hex %valueEscapedHex | text_char %valueEscapedChar); 36 | value_raw_chars = (text_char - [\\"])+ >valueRawStart %valueRawEnd; 37 | varvalue = ('"' . ('' | ( escape_seq | value_raw_chars)**) . '"'); 38 | uset = ("uset" . whitespace+ . varname . whitespace+ . varvalue . whitespace* . comment?); 39 | line = whitespace* . uset; 40 | }%% -------------------------------------------------------------------------------- /src/JobListSelector.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "JobListSelector.hpp" 3 | 4 | JobListSelector::JobListSelector(wxWindow * parent, wxWindowID id) 5 | : Ets2StaticBox(parent, id, "Job List") { 6 | wxBoxSizer * contentSizer = getContentSizer(); 7 | 8 | wxBoxSizer * controlsSizer = new wxBoxSizer(wxHORIZONTAL); 9 | contentSizer->Add(controlsSizer, wxSizerFlags().Expand()); 10 | 11 | mJobList = new wxChoice(this, wxID_ANY); 12 | mJobList->Append(std::vector {L"Automatic", L"List 1", L"List 2", L"List 3", L"List 4", L"List 5", L"List 6", L"List 7", L"List 8"}); 13 | mJobList->SetSelection(0); 14 | controlsSizer->Add(mJobList); 15 | 16 | controlsSizer->AddSpacer(wxDLG_UNIT(this, wxPoint(4, 4)).x); 17 | 18 | mAutoListInfo = new wxStaticText(this, wxID_ANY, L"Changes every day at 0:00 UTC."); 19 | controlsSizer->Add(mAutoListInfo, wxSizerFlags().CenterVertical()); 20 | 21 | mJobList->Bind(wxEVT_CHOICE, [this](wxCommandEvent&) { onSetJobList(); }); 22 | } 23 | 24 | int JobListSelector::getJobList() const { 25 | return mJobList->GetSelection() - 1; 26 | } 27 | 28 | void JobListSelector::setJobList(int jobList) { 29 | mJobList->SetSelection(jobList + 1); 30 | onSetJobList(); 31 | } 32 | 33 | void JobListSelector::onSetJobList() { 34 | mAutoListInfo->Show(getJobList() == -1); 35 | } -------------------------------------------------------------------------------- /src/UpdateChecker.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "ShowLastWindowsError.hpp" 5 | 6 | wxDECLARE_EVENT(EVT_UPDATE_CHECKER, wxCommandEvent); 7 | 8 | class UpdateChecker : public wxEvtHandler, public wxThreadHelper { 9 | public: 10 | // Update check possible states 11 | enum class State { 12 | UNKNOWN, 13 | RUNNING, 14 | FINISHED, 15 | CANCELED, 16 | FAILED 17 | }; 18 | // Update check possible results 19 | enum class Result { 20 | UNKNOWN, 21 | UP_TO_DATE, 22 | NEW_BUGFIX, 23 | NEW_VERSION 24 | }; 25 | struct Status { 26 | bool cancel; 27 | State state; 28 | Result result; 29 | }; 30 | 31 | static std::wstring getStatusDescription(Status state); 32 | 33 | UpdateChecker(wxEvtHandler * eventHandler); 34 | ~UpdateChecker(); 35 | void start(); 36 | void cancel(); 37 | Status getStatus(); 38 | 39 | private: 40 | // Flags determining which fields of the status are to be set 41 | static const int SET_CANCEL = 0x01; 42 | static const int SET_STATE = 0x02; 43 | static const int SET_RESULT = 0x04; 44 | static const int SET_ALL = 0x7; 45 | 46 | void setStatus(int flags, bool cancel, State state, Result result); 47 | void sendUpdate(); 48 | wxThread::ExitCode Entry(); 49 | 50 | wxEvtHandler * mEventHandler; 51 | Status mStatus; 52 | wxCriticalSection mStatusLock; 53 | HINTERNET mInternetHandle; 54 | }; 55 | -------------------------------------------------------------------------------- /src/Ets2/Parser/SiiText.rl.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "SiiText.hpp" 3 | 4 | #include "../lib/Utf8ToUtf16.hpp" 5 | 6 | #define RAGEL(...) /* __VA_ARGS__ */ 7 | 8 | #define PARSER_CALLBACK(...) if (!callback(__VA_ARGS__)) return false; 9 | 10 | namespace Ets2::Parser::Sii { 11 | RAGEL(%%{ 12 | machine siiParserText; 13 | 14 | include "SiiText.rl"; 15 | main := file; 16 | }%%) 17 | 18 | %% write data; 19 | 20 | bool Text::parse(const std::string& data, const ParseCallback& callback) { 21 | const char * p; 22 | const char * pe; 23 | const char * eof; 24 | int cs; 25 | const char * start = data.data(); 26 | 27 | %% write init; 28 | 29 | p = start; 30 | pe = start + data.length(); 31 | eof = pe; 32 | 33 | std::string unitClass; 34 | const char * unitClassStart = nullptr; 35 | std::string unitInstance; 36 | const char * unitInstanceStart = nullptr; 37 | std::string attrName; 38 | const char * attrNameStart = nullptr; 39 | std::string attrRawValue; 40 | const char * attrBareValueStart = nullptr; 41 | const char * attrQuotedValueRawStart = nullptr; 42 | std::string attrSourceValue; 43 | const char * attrSourceValueStart = nullptr; 44 | 45 | bool success = false; 46 | 47 | %% write exec; 48 | 49 | //wxLogDebug("Parse %s at state %d", success ? "succeeded" : "failed", cs); 50 | return success; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lib/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_SWAP_H_ 16 | #define RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /src/Ets2/Parser/Cfg.rl.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "Cfg.hpp" 3 | 4 | #include "../lib/Utf8ToUtf16.hpp" 5 | 6 | #define RAGEL(...) /* __VA_ARGS__ */ 7 | 8 | namespace Ets2::Parser { 9 | RAGEL(%%{ 10 | machine cfgParser; 11 | 12 | include "Cfg.rl"; 13 | main := line; 14 | }%%) 15 | 16 | %% write data; 17 | 18 | void Cfg::parse(const std::string& data, CALLBACK_FUNC callback) { 19 | const char * p; 20 | const char * pe; 21 | const char * eof; 22 | int cs; 23 | 24 | const char * bufferStart = data.data(); 25 | const char * bufferEnd = bufferStart + data.length(); 26 | const char * lineStart = bufferStart; 27 | const char * lineEnd = nullptr; 28 | const char * varNameStart = nullptr; 29 | const char * varValueRawStart = nullptr; 30 | std::string line; 31 | std::string varName; 32 | std::string varValue; 33 | std::string empty; 34 | 35 | while (lineStart < bufferEnd) { 36 | lineEnd = lineStart; 37 | while (lineEnd < bufferEnd && *(lineEnd) != '\r' && *(lineEnd) != '\n') { 38 | ++lineEnd; 39 | } 40 | 41 | line.assign(lineStart, lineEnd - lineStart); 42 | p = lineStart; 43 | pe = lineEnd; 44 | eof = pe; 45 | varName.clear(); 46 | varValue.clear(); 47 | 48 | %% write init; 49 | %% write exec; 50 | 51 | if (cs >= cfgParser_first_final) { 52 | callback(line, varName, varValue); 53 | } else { 54 | callback(line, empty, empty); 55 | } 56 | 57 | lineStart = lineEnd; 58 | if (lineStart < bufferEnd && *lineStart == '\r') { 59 | ++lineStart; 60 | } 61 | if (lineStart < bufferEnd && *lineStart == '\n') { 62 | ++lineStart; 63 | } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/Ets2/Save.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Object.hpp" 4 | #include "ObjectList.hpp" 5 | 6 | #include 7 | #include 8 | 9 | namespace Ets2 { 10 | class Save; 11 | typedef ObjectList SaveList; 12 | 13 | class Save : public Object { 14 | public: 15 | Save(Game game, const std::wstring directory); 16 | 17 | struct Job { 18 | std::string cargo; 19 | std::string target; 20 | int urgency; 21 | int distance; 22 | int ferryTime; 23 | int ferryPrice; 24 | std::string companyTruck; 25 | std::string trailerVariant; 26 | std::string trailerDefinition; 27 | int unitsCount; 28 | int fillRatio; 29 | int trailerPlace; 30 | }; 31 | 32 | typedef std::map> JobList; 33 | typedef std::vector DlcList; 34 | 35 | const DlcList& getDlcs() const; 36 | static void setupBlankJob(Job& job); 37 | int replaceJobList(const JobList& jobs, const std::function& callback) const; 38 | 39 | private: 40 | static const std::wstring SII_BASENAME; 41 | static const std::wstring SAVE_BASENAME; 42 | static const std::string NAME_ATTRIBUTE; 43 | static const std::string SAVE_TIME_ATTRIBUTE; 44 | static const std::string DEPEND_ATTRIBUTE; 45 | static const std::string ECONOMY_UNIT; 46 | static const std::string GAME_TIME_ATTRIBUTE; 47 | static const std::string COMPANY_UNIT; 48 | static const std::string JOB_UNIT; 49 | static const std::string COMPANY_NAME_PREFIX; 50 | 51 | DlcList mDlcs; 52 | 53 | virtual void processAttribute(Parser::Sii::Context context, const std::string& attribute, const std::string& value) override; 54 | virtual bool validate() override; 55 | }; 56 | } -------------------------------------------------------------------------------- /src/JobSyncer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Ets2\Save.hpp" 4 | #include 5 | 6 | wxDECLARE_EVENT(EVT_JOB_SYNCER_UPDATE, wxCommandEvent); 7 | 8 | #define SYNC_DEBUG_LOG(fmt, ...) DEBUG_LOG(wxString(L"Save \"%s\": ")+wxString(fmt), mSave == nullptr ? L"null" : mSave->getName(), __VA_ARGS__) 9 | 10 | class JobSyncer : public wxEvtHandler, public wxThreadHelper { 11 | public: 12 | enum class SyncType { 13 | SYNC, 14 | CLEAR, 15 | RESET_ECONOMY 16 | }; 17 | JobSyncer(wxEvtHandler * eventHandler, SyncType syncType); 18 | ~JobSyncer(); 19 | 20 | enum class State { 21 | NOT_STARTED, 22 | STARTING, 23 | DOWNLOADING, 24 | INSERTING_JOBS, 25 | FINISHED, 26 | CANCELED, 27 | FAILED, 28 | OUTDATED 29 | }; 30 | 31 | struct Status { 32 | State state; 33 | int progress; 34 | wxString message; 35 | }; 36 | 37 | void start(const Ets2::Save * save, const Ets2::Save::DlcList& dlcs, int jobList); 38 | const Status getStatus(); 39 | void cancel(); 40 | 41 | private: 42 | static const int SET_STATE = 1 << 0; 43 | static const int SET_PROGRESS = 1 << 1; 44 | static const int SET_MESSAGE = 1 << 2; 45 | static const int SET_ALL = SET_STATE | SET_PROGRESS | SET_MESSAGE; 46 | 47 | static const int PROGRESS_UNDEFINED = -1; 48 | 49 | static const int DOWNLOAD_CHUNK = 16384; 50 | 51 | wxEvtHandler * mEventHandler; 52 | SyncType mSyncType; 53 | HINTERNET mInternetHandle; 54 | Status mStatus; 55 | wxCriticalSection mStatusLock; 56 | bool mCancel; 57 | wxCriticalSection mCancelLock; 58 | const Ets2::Save * mSave; 59 | Ets2::Save::DlcList mDlcs; 60 | int mJobList; 61 | 62 | void setStatus(int flags, State state, int progress, wxString message); 63 | wxThread::ExitCode Entry(); 64 | bool getJobs(Ets2::Save::JobList& jobs); 65 | }; 66 | -------------------------------------------------------------------------------- /src/MainWindow.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "AboutWindow.hpp" 4 | #include "Ets2StaticBox.hpp" 5 | #include "GameSettingsPanel.hpp" 6 | #include "ProfileSelector.hpp" 7 | #include "SaveSelector.hpp" 8 | #include "DlcSelector.hpp" 9 | #include "JobListSelector.hpp" 10 | #include "SyncDialog.hpp" 11 | 12 | #include 13 | #include 14 | 15 | // Main Application Window 16 | class MainWindow : public wxFrame { 17 | public: 18 | MainWindow(const wxString& title); 19 | ~MainWindow(); 20 | 21 | void openWebsite(); 22 | 23 | private: 24 | enum ids { 25 | ID_OPEN_WEBSITE = wxID_HIGHEST + 1, 26 | ID_DARK_MODE = ID_OPEN_WEBSITE + 1 27 | }; 28 | // How long to wait after a FileSystemWatcher event before re-reading the game folder 29 | static const int FSTIMER_DELAY = 2000; 30 | 31 | Ets2::Info * mEts2Info; 32 | wxFileSystemWatcher * mFSWatcher; 33 | wxTimer * mFSTimer; 34 | class AboutWindow * mAboutWindow; 35 | std::vector mEts2Children; 36 | GameSettingsPanel * mGameSettingsPanel; 37 | ProfileSelector * mProfileSelector; 38 | SaveSelector * mSaveSelector; 39 | DlcSelector * mDlcSelector; 40 | JobListSelector * mJobListSelector; 41 | wxButton * mSyncButton; 42 | wxButton * mClearJobsButton; 43 | wxButton * mResetEconomyButton; 44 | SyncDialog * mSyncDialog; 45 | 46 | const Ets2::Profile * getSelectedProfile() const; 47 | const Ets2::Save * getSelectedSave() const; 48 | 49 | void updateEts2Info(std::wstring directory, std::wstring steamDirectory); 50 | void onAbout(); 51 | void onConfigDirChanged(); 52 | void onSteamDirChanged(); 53 | void onFileSystemWatcher(); 54 | void onFileSystemTimer(); 55 | void onProfileChanged(); 56 | void onSaveChanged(); 57 | void onSync(); 58 | void onClearJobs(); 59 | void onResetEconomy(); 60 | }; 61 | 62 | -------------------------------------------------------------------------------- /src/Ets2/Info.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Profile.hpp" 4 | #include "lib/file.hpp" 5 | #include 6 | #include 7 | 8 | namespace Ets2 { 9 | enum class Game : unsigned int { 10 | ETS2, 11 | ATS 12 | }; 13 | 14 | // Information from a ETS2 Settings directory 15 | class Info { 16 | public: 17 | class SaveFormatChangeFailed : public std::exception { 18 | const char * what() const throw() { return "Save Format change failed."; } 19 | }; 20 | 21 | // Returns the default ETS2 Settings directory for the current user 22 | // i.e. the current user's Documents\\Euro Truck Simulator 2 23 | enum class SaveFormat : int { 24 | BINARY = 0, 25 | TEXT = 2, 26 | BOTH = 3, 27 | INVALID = -1, 28 | NOT_FOUND = -2 29 | }; 30 | 31 | static std::wstring getDefaultDirectory(Game game, bool isSteam = false); 32 | 33 | Info(Game game, const std::wstring directory, const std::wstring steamDirectory); 34 | Info(Info& info); 35 | 36 | bool isValid(); 37 | std::wstring getDirectory(); 38 | std::wstring getSteamDirectory(); 39 | std::wstring getConfigFileName(); 40 | Game getGame() const; 41 | SaveFormat getSaveFormat(); 42 | void changeSaveFormat(SaveFormat newFormat); 43 | std::wstring getRawSaveFormat(); 44 | const ProfileList& getProfiles() const; 45 | 46 | private: 47 | static const std::string SAVE_FORMAT_VAR_NAME; 48 | 49 | bool mIsValid; 50 | std::wstring mDirectory; 51 | std::wstring mSteamDirectory; 52 | std::wstring mConfigFileName; 53 | Game mGame; 54 | ProfileList mProfiles; 55 | std::wstring mRawSaveFormat; 56 | SaveFormat mSaveFormat; 57 | 58 | // If called with SAVE_FORMAT_INVALID, reads the save format and 59 | // sets mSaveFormat and mSaveFormatLine, otherwise changes the 60 | // save format in the file. 61 | void processSaveFormat(SaveFormat newFormat = SaveFormat::INVALID); 62 | }; 63 | } -------------------------------------------------------------------------------- /src/Ets2/Object.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Parser/Sii.hpp" 4 | 5 | #include 6 | #include 7 | 8 | namespace Ets2 { 9 | enum class Game : unsigned int; 10 | 11 | class Object { 12 | public: 13 | Object(const std::wstring& siiFileBasename); 14 | 15 | // This is used to load and process the file passed as siiFileBasename to the constructor from the directory. 16 | // Should be called from the constructor of a derived class. 17 | void init(const std::wstring& directory); 18 | 19 | // For ObjectList::sort 20 | static bool compareForSort(const Object * left, const Object * right) { 21 | return left->mSaveTime > right->mSaveTime; 22 | } 23 | 24 | bool isValid(); 25 | std::wstring getDirectory() const; 26 | Game getGame() const; 27 | std::wstring getName() const; 28 | time_t getSaveTime() const; 29 | const std::wstring getSaveTimeCaption() const; 30 | 31 | protected: 32 | std::wstring mDirectory; 33 | Game mGame; 34 | std::wstring mName; 35 | time_t mSaveTime; 36 | 37 | // This function is called during init() for every attribute/value pair read from the file. 38 | // It should set mName (else the object will be named "[no name]") and 39 | // it must set mSaveTime (else the object will be considered invalid) 40 | virtual void processAttribute(Parser::Sii::Context context, const std::string& name, const std::string& value) = 0; 41 | 42 | // This function is called after all attributes have been sent to processAttribute. 43 | // Its return value determines whether the object is valid (true) or not (false). 44 | // Note that an object that fails parsing or has no save time is always invalid. 45 | virtual bool validate() = 0; 46 | 47 | private: 48 | const std::wstring mSiiFileBasename; 49 | const std::wstring mNameAttribute; 50 | const std::wstring mSaveTimeAttribute; 51 | 52 | bool mIsValid; 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /src/Ets2/Object.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "Object.hpp" 3 | 4 | #include "lib/Utf8ToUtf16.hpp" 5 | #include "lib/file.hpp" 6 | #include "File.hpp" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Ets2 { 13 | Object::Object(const std::wstring& siiFileBasename) : mSiiFileBasename(siiFileBasename) { 14 | mIsValid = false; 15 | } 16 | 17 | void Object::init(const std::wstring& directory) { 18 | mIsValid = false; 19 | mName.clear(); 20 | mSaveTime = 0; 21 | mDirectory = directory; 22 | 23 | std::string data; 24 | if (!File::read(directory + L"\\" + mSiiFileBasename, data)) { 25 | return; 26 | } 27 | //write_file(data, directory + L"\\" + mSiiFileBasename + L".raw.txt"); 28 | 29 | if (!File::parse(data, [this](Parser::Sii::Context context, const std::string& name, const std::string& value, const std::string& /* sourceValue */, unsigned long /* offset */) -> bool { 30 | processAttribute(context, name, value); 31 | return true; 32 | })) { 33 | return; 34 | } 35 | 36 | if (mSaveTime == 0) { 37 | return; 38 | } 39 | 40 | mIsValid = validate(); 41 | } 42 | 43 | bool Object::isValid() { 44 | return mIsValid; 45 | } 46 | 47 | std::wstring Object::getDirectory() const { 48 | return mDirectory; 49 | } 50 | 51 | Game Object::getGame() const { 52 | return mGame; 53 | } 54 | 55 | std::wstring Object::getName() const { 56 | return mName; 57 | } 58 | 59 | time_t Object::getSaveTime() const { 60 | return mSaveTime; 61 | } 62 | 63 | const std::wstring Object::getSaveTimeCaption() const { 64 | wxDateTime now = wxDateTime::Now(); 65 | wxDateTime saved = wxDateTime(getSaveTime()); 66 | wxTimeSpan age = now - saved; 67 | if (age.GetMinutes() == 0) { 68 | return wxString::Format(age.GetSeconds() == 1 ? L"%lld second ago" : L"%lld seconds ago", age.GetSeconds()).ToStdWstring(); 69 | } else if (age.GetHours() == 0) { 70 | return wxString::Format(age.GetMinutes() == 1 ? L"%d minute ago" : L"%d minutes ago", age.GetMinutes()).ToStdWstring(); 71 | } 72 | return saved.Format().ToStdWstring(); 73 | } 74 | } -------------------------------------------------------------------------------- /src/GameSettingsPanel.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Ets2StaticBox.hpp" 4 | #include "StatusText.hpp" 5 | #include 6 | #include "precomp.hpp" 7 | 8 | wxDECLARE_EVENT(EVT_CONFIG_DIR_CHANGED, wxCommandEvent); 9 | wxDECLARE_EVENT(EVT_STEAM_DIR_CHANGED, wxCommandEvent); 10 | 11 | class GameSettingsPanel : public Ets2StaticBox { 12 | public: 13 | GameSettingsPanel(wxWindow * parent, wxWindowID id); 14 | ~GameSettingsPanel(); 15 | 16 | enum MenuId : int { 17 | MENU_ID_DIR_OPEN = wxID_HIGHEST + 1, 18 | MENU_ID_DIR_OPEN_FILE, 19 | MENU_ID_DIR_CHANGE, 20 | MENU_ID_DIR_CHECK_AGAIN, 21 | MENU_ID_DIR_DEFAULT 22 | }; 23 | 24 | enum DirId : int { 25 | CONFIG, 26 | STEAM 27 | }; 28 | 29 | void updateFromEts2Info() override; 30 | wxString getDirectory(DirId dirId = DirId::CONFIG); 31 | Ets2::Game getGame(); 32 | void setGame(Ets2::Game game, bool sendEvend = true); 33 | 34 | private: 35 | Ets2::Game mGame; 36 | wxRadioButton * mGameEts2; 37 | wxRadioButton * mGameAts; 38 | wxBoxSizer * mConfigDirSizer; 39 | wxStaticText * mConfigDirText; 40 | wxStaticText * mConfigDirSeparator; 41 | wxHyperlinkCtrl * mConfigDirOptionsButton; 42 | wxMenu * mConfigDirOptionsMenu; 43 | wxMenuItem * mConfigDirOptionOpen; 44 | wxMenuItem * mConfigDirOptionOpenFile; 45 | wxMenuItem * mConfigDirOptionDefault; 46 | wxBoxSizer * mSteamDirSizer; 47 | wxStaticText * mSteamDirText; 48 | wxStaticText * mSteamDirSeparator; 49 | wxHyperlinkCtrl * mSteamDirOptionsButton; 50 | wxMenu * mSteamDirOptionsMenu; 51 | wxMenuItem * mSteamDirOptionOpen; 52 | wxMenuItem * mSteamDirOptionDefault; 53 | wxBoxSizer * mSaveFormatSizer; 54 | wxStaticText * mSaveFormatText; 55 | wxStaticText * mSaveFormatSeparator; 56 | wxHyperlinkCtrl * mFixSaveFormatButton; 57 | StatusText * mStatusText; 58 | 59 | void onDirOptions(DirId dirId); 60 | wxString onDirOptionsSelected(wxCommandEvent& event, DirId dirId, wxString text, wxString default, wxString label, wxString baseText); 61 | void onConfigDirOptionSelected(wxCommandEvent& event); 62 | void onSteamDirOptionSelected(wxCommandEvent& event); 63 | void setDirText(const wxString& text, DirId dirId); 64 | }; -------------------------------------------------------------------------------- /src/ObjectSelector.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Ets2StaticBox.hpp" 4 | #include "StatusText.hpp" 5 | #include "ObjectCombobox.hpp" 6 | 7 | template class ObjectSelector : public Ets2StaticBox { 8 | public: 9 | ObjectSelector (wxWindow * parent, wxWindowID id) 10 | : Ets2StaticBox(parent, id, L"") { 11 | 12 | wxBoxSizer * contentSizer = getContentSizer(); 13 | 14 | mStatusText = new StatusText(this, wxID_ANY); 15 | contentSizer->Add(mStatusText); 16 | 17 | contentSizer->AddSpacer(wxDLG_UNIT(this, wxPoint(0, 4)).y); 18 | 19 | mCombobox = new ObjectCombobox(this, wxID_ANY); 20 | contentSizer->Add(mCombobox, wxSizerFlags().Expand()); 21 | mCombobox->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent&){ onObjectChanged(); }); 22 | } 23 | 24 | int GetSelection() { 25 | return mCombobox->GetSelection(); 26 | } 27 | 28 | void setList(const Ets2::ObjectList * list) { 29 | std::wstring gameString = getEts2Info()->getGame() == Ets2::Game::ATS ? L"ATS" : L"ETS2"; 30 | SetLabel(wxString::Format(mLabel, gameString)); 31 | 32 | if (!list) { 33 | mStatusText->SetLabel(L"", StatusText::Type::STATUS); 34 | mCombobox->clearList(); 35 | return; 36 | } 37 | 38 | size_t numObjects = list->size(); 39 | 40 | wxString& formatString = (numObjects == 0 ? mFormatZero : (numObjects == 1 ? mFormatOne : mFormatPlural)); 41 | wxString formattedString = (numObjects > 1 ? wxString::Format(formatString, numObjects, gameString) : wxString::Format(formatString, gameString)); 42 | mStatusText->SetLabel(formattedString, numObjects == 0 ? StatusText::Type::FAILURE : StatusText::Type::SUCCESS); 43 | 44 | mCombobox->setList(list); 45 | if (numObjects == 0) { 46 | mCombobox->Disable(); 47 | } else { 48 | mCombobox->Enable(); 49 | mCombobox->SetSelection(0); 50 | } 51 | } 52 | 53 | void updateFromEts2Info() { 54 | setList(getList()); 55 | }; 56 | 57 | private: 58 | StatusText * mStatusText; 59 | ObjectCombobox * mCombobox; 60 | 61 | static wxString mLabel; 62 | static wxString mFormatZero; 63 | static wxString mFormatOne; 64 | static wxString mFormatPlural; 65 | 66 | const Ets2::ObjectList * getList(); 67 | void onObjectChanged(); 68 | }; 69 | 70 | template void ObjectSelector::onObjectChanged() {}; 71 | template const Ets2::ObjectList * ObjectSelector::getList() { return nullptr; } -------------------------------------------------------------------------------- /src/Ets2/File.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Parser/Sii.hpp" 4 | 5 | #include 6 | 7 | namespace Ets2 { 8 | class File { 9 | public: 10 | // Reads a game file and, if encrypted or binary, convert to plaintext 11 | // contents: string in which to place the file contents 12 | static bool read(const std::wstring fileName, std::string& contents); 13 | 14 | // Holds the pointers to the output buffer for each attribute 15 | struct ATTRIBUTE_POINTERS { 16 | char * attrStart; 17 | size_t attrLength; 18 | char * valueStart; 19 | size_t valueLength; 20 | bool valueUtf8; 21 | }; 22 | 23 | // Parses a plaintext game file 24 | //static bool parse(const std::string& contents, std::string& output, std::vector& attributes); 25 | static bool parse(const std::string& contents, const Parser::Sii::ParseCallback& callback); 26 | 27 | private: 28 | // Convenience map to the encrypted data 29 | struct ENCRYPTED_DATA { 30 | unsigned char iv[16]; 31 | unsigned int dataSize; 32 | unsigned char ciphertext[1]; // It's not actually just one character, you know... 33 | }; 34 | 35 | // Stores an AES-256 key blob in the format expected by Windows 36 | struct AES256_KEY_BLOB { 37 | PUBLICKEYSTRUC header; 38 | DWORD keySize; 39 | BYTE key[32]; 40 | }; 41 | 42 | // Magic headers 43 | static const std::string SII_MAGIC_ENCRYPTED; 44 | static const std::string SII_MAGIC_TEXT; 45 | static const std::string SII_MAGIC_BINARY; 46 | 47 | // The key used to encrypt/decrypt files with "ScsC" magic 48 | static const unsigned char AES_KEY[32]; 49 | 50 | // Unpacks game file data and returns its plaintext version (regardless of whether it's encrypted or binary) 51 | // data: file contents (modified but meaningless on return) 52 | // plaintext: output 53 | // fileName: file name (for error messages) 54 | static bool unpack(const std::string& data, std::string& plaintext, const std::wstring& fileName); 55 | 56 | // Decrypts the data (in-place) 57 | static bool decrypt(ENCRYPTED_DATA * data, size_t dataSize, const std::wstring& fileName); 58 | 59 | // Inflates the data 60 | // data: deflated data 61 | // plaintext: inflated data 62 | // fileName: file name (for error messages) 63 | static bool inflate(const ENCRYPTED_DATA * data, size_t dataSize, std::string& plaintext, const std::wstring& fileName); 64 | }; 65 | } 66 | -------------------------------------------------------------------------------- /lib/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 16 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | #include 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | namespace internal { 23 | 24 | //! Custom strlen() which works on different character types. 25 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 26 | \param s Null-terminated input string. 27 | \return Number of characters in the string. 28 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 29 | */ 30 | template 31 | inline SizeType StrLen(const Ch* s) { 32 | RAPIDJSON_ASSERT(s != 0); 33 | const Ch* p = s; 34 | while (*p) ++p; 35 | return SizeType(p - s); 36 | } 37 | 38 | template <> 39 | inline SizeType StrLen(const char* s) { 40 | return SizeType(std::strlen(s)); 41 | } 42 | 43 | template <> 44 | inline SizeType StrLen(const wchar_t* s) { 45 | return SizeType(std::wcslen(s)); 46 | } 47 | 48 | //! Returns number of code points in a encoded string. 49 | template 50 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 51 | RAPIDJSON_ASSERT(s != 0); 52 | RAPIDJSON_ASSERT(outCount != 0); 53 | GenericStringStream is(s); 54 | const typename Encoding::Ch* end = s + length; 55 | SizeType count = 0; 56 | while (is.src_ < end) { 57 | unsigned codepoint; 58 | if (!Encoding::Decode(is, &codepoint)) 59 | return false; 60 | count++; 61 | } 62 | *outCount = count; 63 | return true; 64 | } 65 | 66 | } // namespace internal 67 | RAPIDJSON_NAMESPACE_END 68 | 69 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 70 | -------------------------------------------------------------------------------- /src/ShowLastWindowsError.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "ShowLastWindowsError.hpp" 3 | 4 | #include 5 | 6 | void ShowLastWindowsError(const wchar_t * task) { 7 | DWORD lastError = GetLastError(); 8 | 9 | // WinInet extended error message 10 | if (lastError == ERROR_INTERNET_EXTENDED_ERROR) { 11 | lastError = 0; 12 | DWORD lastErrorSize = 0; 13 | if (!InternetGetLastResponseInfo(&lastError, NULL, &lastErrorSize) && GetLastError() == ERROR_INSUFFICIENT_BUFFER) { 14 | wchar_t * message = new wchar_t[lastErrorSize + 1]; 15 | if (!InternetGetLastResponseInfo(&lastError, NULL, &lastErrorSize)) { 16 | wxLogError("%s error 0x%08X: ", task, GetLastError()); 17 | return; 18 | } 19 | DWORD idx = lastErrorSize; 20 | while (--idx >= 0 && (message[idx] == '\n' || message[idx] == '\r')) 21 | message[idx] = '\0'; 22 | wxLogError("%s\n\n%s error 0x%08X:", message, task, lastError); 23 | delete[] message; 24 | return; 25 | } else { 26 | wxLogError("%s error 0x%08X: ", task, lastError); 27 | return; 28 | } 29 | } else if (lastError >= INTERNET_ERROR_BASE && lastError <= INTERNET_ERROR_LAST) { 30 | wchar_t * message = NULL; 31 | DWORD messageLength = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, 32 | GetModuleHandle(L"wininet"), lastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&message, 0, NULL); 33 | if (messageLength) { 34 | DWORD idx = messageLength; 35 | while (--idx >= 0 && (message[idx] == '\n' || message[idx] == '\r')) 36 | message[idx] = '\0'; 37 | wxLogError("%s\n\n%s error 0x%08X", message, task, lastError); 38 | } else { 39 | wxLogError("%s error 0x%08X: ", task, lastError); 40 | } 41 | return; 42 | } 43 | 44 | wchar_t * message = NULL; 45 | DWORD messageLength = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 46 | NULL, lastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&message, 0, NULL); 47 | if (messageLength) { 48 | DWORD idx = messageLength; 49 | while (--idx >= 0 && (message[idx] == '\n' || message[idx] == '\r')) 50 | message[idx] = '\0'; 51 | wxLogError("%s\n\n%s error 0x%08X", message, task, lastError); 52 | } else { 53 | wxLogError("%s error 0x%08X: ", task, lastError); 54 | } 55 | } -------------------------------------------------------------------------------- /lib/rapidjson/cursorstreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_CURSORSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_CURSORSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | 20 | #if defined(__GNUC__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(effc++) 23 | #endif 24 | 25 | #if defined(_MSC_VER) && _MSC_VER <= 1800 26 | RAPIDJSON_DIAG_PUSH 27 | RAPIDJSON_DIAG_OFF(4702) // unreachable code 28 | RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated 29 | #endif 30 | 31 | RAPIDJSON_NAMESPACE_BEGIN 32 | 33 | 34 | //! Cursor stream wrapper for counting line and column number if error exists. 35 | /*! 36 | \tparam InputStream Any stream that implements Stream Concept 37 | */ 38 | template > 39 | class CursorStreamWrapper : public GenericStreamWrapper { 40 | public: 41 | typedef typename Encoding::Ch Ch; 42 | 43 | CursorStreamWrapper(InputStream& is): 44 | GenericStreamWrapper(is), line_(1), col_(0) {} 45 | 46 | // counting line and column number 47 | Ch Take() { 48 | Ch ch = this->is_.Take(); 49 | if(ch == '\n') { 50 | line_ ++; 51 | col_ = 0; 52 | } else { 53 | col_ ++; 54 | } 55 | return ch; 56 | } 57 | 58 | //! Get the error line number, if error exists. 59 | size_t GetLine() const { return line_; } 60 | //! Get the error column number, if error exists. 61 | size_t GetColumn() const { return col_; } 62 | 63 | private: 64 | size_t line_; //!< Current Line 65 | size_t col_; //!< Current Column 66 | }; 67 | 68 | #if defined(_MSC_VER) && _MSC_VER <= 1800 69 | RAPIDJSON_DIAG_POP 70 | #endif 71 | 72 | #if defined(__GNUC__) 73 | RAPIDJSON_DIAG_POP 74 | #endif 75 | 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_ 79 | -------------------------------------------------------------------------------- /lib/rapidjson/ostreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_OSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_OSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. 29 | /*! 30 | The classes can be wrapped including but not limited to: 31 | 32 | - \c std::ostringstream 33 | - \c std::stringstream 34 | - \c std::wpstringstream 35 | - \c std::wstringstream 36 | - \c std::ifstream 37 | - \c std::fstream 38 | - \c std::wofstream 39 | - \c std::wfstream 40 | 41 | \tparam StreamType Class derived from \c std::basic_ostream. 42 | */ 43 | 44 | template 45 | class BasicOStreamWrapper { 46 | public: 47 | typedef typename StreamType::char_type Ch; 48 | BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} 49 | 50 | void Put(Ch c) { 51 | stream_.put(c); 52 | } 53 | 54 | void Flush() { 55 | stream_.flush(); 56 | } 57 | 58 | // Not implemented 59 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 60 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 61 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 62 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 63 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 64 | 65 | private: 66 | BasicOStreamWrapper(const BasicOStreamWrapper&); 67 | BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); 68 | 69 | StreamType& stream_; 70 | }; 71 | 72 | typedef BasicOStreamWrapper OStreamWrapper; 73 | typedef BasicOStreamWrapper WOStreamWrapper; 74 | 75 | #ifdef __clang__ 76 | RAPIDJSON_DIAG_POP 77 | #endif 78 | 79 | RAPIDJSON_NAMESPACE_END 80 | 81 | #endif // RAPIDJSON_OSTREAMWRAPPER_H_ 82 | -------------------------------------------------------------------------------- /lib/rapidjson/memorybuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYBUFFER_H_ 16 | #define RAPIDJSON_MEMORYBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | 23 | //! Represents an in-memory output byte stream. 24 | /*! 25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. 26 | 27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. 28 | 29 | Differences between MemoryBuffer and StringBuffer: 30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. 31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. 32 | 33 | \tparam Allocator type for allocating memory buffer. 34 | \note implements Stream concept 35 | */ 36 | template 37 | struct GenericMemoryBuffer { 38 | typedef char Ch; // byte 39 | 40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 41 | 42 | void Put(Ch c) { *stack_.template Push() = c; } 43 | void Flush() {} 44 | 45 | void Clear() { stack_.Clear(); } 46 | void ShrinkToFit() { stack_.ShrinkToFit(); } 47 | Ch* Push(size_t count) { return stack_.template Push(count); } 48 | void Pop(size_t count) { stack_.template Pop(count); } 49 | 50 | const Ch* GetBuffer() const { 51 | return stack_.template Bottom(); 52 | } 53 | 54 | size_t GetSize() const { return stack_.GetSize(); } 55 | 56 | static const size_t kDefaultCapacity = 256; 57 | mutable internal::Stack stack_; 58 | }; 59 | 60 | typedef GenericMemoryBuffer<> MemoryBuffer; 61 | 62 | //! Implement specialized version of PutN() with memset() for better performance. 63 | template<> 64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { 65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 71 | -------------------------------------------------------------------------------- /lib/rapidjson/memorystream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYSTREAM_H_ 16 | #define RAPIDJSON_MEMORYSTREAM_H_ 17 | 18 | #include "stream.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(unreachable-code) 23 | RAPIDJSON_DIAG_OFF(missing-noreturn) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Represents an in-memory input byte stream. 29 | /*! 30 | This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. 31 | 32 | It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. 33 | 34 | Differences between MemoryStream and StringStream: 35 | 1. StringStream has encoding but MemoryStream is a byte stream. 36 | 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. 37 | 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). 38 | \note implements Stream concept 39 | */ 40 | struct MemoryStream { 41 | typedef char Ch; // byte 42 | 43 | MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} 44 | 45 | Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } 46 | Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } 47 | size_t Tell() const { return static_cast(src_ - begin_); } 48 | 49 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 50 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 51 | void Flush() { RAPIDJSON_ASSERT(false); } 52 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 53 | 54 | // For encoding detection only. 55 | const Ch* Peek4() const { 56 | return Tell() + 4 <= size_ ? src_ : 0; 57 | } 58 | 59 | const Ch* src_; //!< Current read position. 60 | const Ch* begin_; //!< Original head of the string. 61 | const Ch* end_; //!< End of stream. 62 | size_t size_; //!< Size of the stream. 63 | }; 64 | 65 | RAPIDJSON_NAMESPACE_END 66 | 67 | #ifdef __clang__ 68 | RAPIDJSON_DIAG_POP 69 | #endif 70 | 71 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 72 | -------------------------------------------------------------------------------- /src/Ets2/Parser/SiiBinary.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Sii.hpp" 4 | 5 | #include 6 | #include 7 | 8 | namespace Ets2::Parser::Sii { 9 | class Binary { 10 | public: 11 | static bool parse(const std::string& data, const ParseCallback& callback); 12 | 13 | Binary(const std::string& data, const ParseCallback& callback); 14 | ~Binary(); 15 | 16 | bool parseSuccessful(); 17 | 18 | private: 19 | enum PropertyType { 20 | INVALID, 21 | STRING, 22 | STRING_ARRAY, 23 | TOKEN, 24 | TOKEN_ARRAY, 25 | FLOAT, 26 | FLOAT_ARRAY, 27 | FLOAT_TRIPLE, 28 | FLOAT_QUAD, 29 | UINT32_TRIPLE, 30 | INT32_TRIPLE, 31 | INT32_TRIPLE_ARRAY, 32 | FLOAT_QUAD_ARRAY, 33 | FLOAT_TRIPLE_QUAD, // Not a quad of triples, but a triple followed by four bytes (?) followed by a quad 34 | INT32, 35 | UINT32, 36 | UINT32_ARRAY, 37 | UINT16, 38 | UINT16_ARRAY, 39 | INT64, 40 | UINT64, 41 | INT64_ARRAY, 42 | BOOLEAN, 43 | BOOLEAN_ARRAY, 44 | UNIT, 45 | UNIT_ARRAY 46 | }; 47 | 48 | static const int PropertyTypeByIndex[62]; 49 | static const int PropertyArrayTypesToBase[62]; 50 | 51 | #pragma pack(push, 1) 52 | struct UnitDeclarationHeader { 53 | int flag; 54 | int format; 55 | char index1; 56 | int index2; 57 | int nameLength; 58 | }; 59 | 60 | struct PropertyDeclarationHeader { 61 | int type; 62 | int nameLength; 63 | }; 64 | #pragma pack(pop) 65 | 66 | struct PropertyDeclaration { 67 | PropertyType type; 68 | std::string name; 69 | }; 70 | 71 | struct UnitDeclaration { 72 | int index; 73 | std::string name; 74 | std::vector properties; 75 | }; 76 | 77 | class EndOfData : public std::runtime_error { 78 | public: 79 | EndOfData() : runtime_error("no more data") { 80 | }; 81 | }; 82 | 83 | class ParseError : public std::runtime_error { 84 | public: 85 | ParseError(std::string what) : runtime_error("parse error: " + what) { 86 | } 87 | }; 88 | 89 | bool mParseSuccessful; 90 | const std::string& mData; 91 | const ParseCallback& mCallback; 92 | const char * mCursor; 93 | const char * mEnd; 94 | 95 | std::map mUnitDeclarations; 96 | 97 | bool parse(); 98 | 99 | // Takes mCursor to be pointing to a record n bytes long. 100 | // Returns a pointer to the first byte of the record (i.e. mCursor when it is called). 101 | // Advances mCursor to the first byte after the record. 102 | // Throws EndOfData if reading n bytes would read past the end of data. 103 | void * getBytes(size_t n); 104 | 105 | int getInt(); 106 | 107 | void readUnitDeclarations(); 108 | void readPropertyDeclarations(UnitDeclaration * unit); 109 | 110 | bool readUnits(); 111 | bool readProperty(PropertyType type, const std::string& name, bool arrayMember, uint32_t arrayIndex); 112 | 113 | void readValue(PropertyType type, std::string& dest, std::string * destRaw); 114 | 115 | void readUnitName(std::string& dest); 116 | int decodeToken(uint64_t token, char dest[12]); 117 | }; 118 | } 119 | -------------------------------------------------------------------------------- /lib/rapidjson/internal/ieee754.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_IEEE754_ 16 | #define RAPIDJSON_IEEE754_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | class Double { 24 | public: 25 | Double() {} 26 | Double(double d) : d_(d) {} 27 | Double(uint64_t u) : u_(u) {} 28 | 29 | double Value() const { return d_; } 30 | uint64_t Uint64Value() const { return u_; } 31 | 32 | double NextPositiveDouble() const { 33 | RAPIDJSON_ASSERT(!Sign()); 34 | return Double(u_ + 1).Value(); 35 | } 36 | 37 | bool Sign() const { return (u_ & kSignMask) != 0; } 38 | uint64_t Significand() const { return u_ & kSignificandMask; } 39 | int Exponent() const { return static_cast(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); } 40 | 41 | bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; } 42 | bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; } 43 | bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; } 44 | bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; } 45 | bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; } 46 | 47 | uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); } 48 | int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; } 49 | uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; } 50 | 51 | static int EffectiveSignificandSize(int order) { 52 | if (order >= -1021) 53 | return 53; 54 | else if (order <= -1074) 55 | return 0; 56 | else 57 | return order + 1074; 58 | } 59 | 60 | private: 61 | static const int kSignificandSize = 52; 62 | static const int kExponentBias = 0x3FF; 63 | static const int kDenormalExponent = 1 - kExponentBias; 64 | static const uint64_t kSignMask = RAPIDJSON_UINT64_C2(0x80000000, 0x00000000); 65 | static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); 66 | static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); 67 | static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); 68 | 69 | union { 70 | double d_; 71 | uint64_t u_; 72 | }; 73 | }; 74 | 75 | } // namespace internal 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_IEEE754_ 79 | -------------------------------------------------------------------------------- /lib/rapidjson/filereadstream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_FILEREADSTREAM_H_ 16 | #define RAPIDJSON_FILEREADSTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | RAPIDJSON_DIAG_OFF(unreachable-code) 25 | RAPIDJSON_DIAG_OFF(missing-noreturn) 26 | #endif 27 | 28 | RAPIDJSON_NAMESPACE_BEGIN 29 | 30 | //! File byte stream for input using fread(). 31 | /*! 32 | \note implements Stream concept 33 | */ 34 | class FileReadStream { 35 | public: 36 | typedef char Ch; //!< Character type (byte). 37 | 38 | //! Constructor. 39 | /*! 40 | \param fp File pointer opened for read. 41 | \param buffer user-supplied buffer. 42 | \param bufferSize size of buffer in bytes. Must >=4 bytes. 43 | */ 44 | FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 45 | RAPIDJSON_ASSERT(fp_ != 0); 46 | RAPIDJSON_ASSERT(bufferSize >= 4); 47 | Read(); 48 | } 49 | 50 | Ch Peek() const { return *current_; } 51 | Ch Take() { Ch c = *current_; Read(); return c; } 52 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); } 53 | 54 | // Not implemented 55 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 56 | void Flush() { RAPIDJSON_ASSERT(false); } 57 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 58 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 59 | 60 | // For encoding detection only. 61 | const Ch* Peek4() const { 62 | return (current_ + 4 <= bufferLast_) ? current_ : 0; 63 | } 64 | 65 | private: 66 | void Read() { 67 | if (current_ < bufferLast_) 68 | ++current_; 69 | else if (!eof_) { 70 | count_ += readCount_; 71 | readCount_ = std::fread(buffer_, 1, bufferSize_, fp_); 72 | bufferLast_ = buffer_ + readCount_ - 1; 73 | current_ = buffer_; 74 | 75 | if (readCount_ < bufferSize_) { 76 | buffer_[readCount_] = '\0'; 77 | ++bufferLast_; 78 | eof_ = true; 79 | } 80 | } 81 | } 82 | 83 | std::FILE* fp_; 84 | Ch *buffer_; 85 | size_t bufferSize_; 86 | Ch *bufferLast_; 87 | Ch *current_; 88 | size_t readCount_; 89 | size_t count_; //!< Number of characters read 90 | bool eof_; 91 | }; 92 | 93 | RAPIDJSON_NAMESPACE_END 94 | 95 | #ifdef __clang__ 96 | RAPIDJSON_DIAG_POP 97 | #endif 98 | 99 | #endif // RAPIDJSON_FILESTREAM_H_ 100 | -------------------------------------------------------------------------------- /src/Ets2/Parser/SiiText.rl: -------------------------------------------------------------------------------- 1 | %%{ 2 | machine siiParserText; 3 | 4 | action unitClassStart { 5 | unitClassStart = p; 6 | } 7 | 8 | action unitClassEnd { 9 | unitClass.assign(unitClassStart, p - unitClassStart); 10 | } 11 | 12 | action unitInstanceStart { 13 | unitInstanceStart = p; 14 | } 15 | 16 | action unitInstanceEnd { 17 | unitInstance.assign(unitInstanceStart, p - unitInstanceStart); 18 | } 19 | 20 | action unitStart { 21 | attrSourceValue.clear(); 22 | PARSER_CALLBACK(Context::UNIT_START, unitClass, unitInstance, attrSourceValue, p - start); 23 | } 24 | 25 | action unitEnd { 26 | attrSourceValue.clear(); 27 | PARSER_CALLBACK(Context::UNIT_END, unitClass, unitInstance, attrSourceValue, p - start); 28 | } 29 | 30 | action attrNameStart { 31 | attrNameStart = p; 32 | } 33 | 34 | action attrNameEnd { 35 | attrName.assign(attrNameStart, p - attrNameStart); 36 | //wxLogDebug("Attr Name: '%s'", attrName); 37 | } 38 | 39 | action attrValueStart { 40 | attrRawValue.clear(); 41 | attrSourceValueStart = p; 42 | } 43 | 44 | action attrValueEnd { 45 | attrSourceValue.assign(attrSourceValueStart, p - attrSourceValueStart); 46 | PARSER_CALLBACK(Context::ATTRIBUTE, attrName, attrRawValue, attrSourceValue, p - start); 47 | //wxLogDebug("Attr Value: '%s' (state %d)", attrRawValue, cs); 48 | } 49 | 50 | action attrBareValueStart { 51 | //wxLogDebug("attrBareValueStart"); 52 | attrBareValueStart = p; 53 | } 54 | 55 | action attrBareValueEnd { 56 | attrRawValue.assign(attrBareValueStart, p - attrBareValueStart); 57 | //wxLogDebug("attrBareValueEnd: %s", attrValue); 58 | } 59 | 60 | action attrQuotedValueRawStart { 61 | //wxLogDebug("QuotedValueRawStart: %p", p); 62 | attrQuotedValueRawStart = p; 63 | } 64 | 65 | action attrQuotedValueRawEnd { 66 | //wxLogDebug("QuotedValueRawEnd: %p '%s'", p, std::string(attrQuotedValueRawStart, p - attrQuotedValueRawStart)); 67 | attrRawValue.append(attrQuotedValueRawStart, p - attrQuotedValueRawStart); 68 | } 69 | 70 | action attrQuotedValueEscapedChar { 71 | attrRawValue.push_back(*(p-1)); 72 | } 73 | 74 | action attrQuotedValueEscapedHex { 75 | attrRawValue.push_back(((p[-2] & 0x40 ? 9 : 0) + (p[-2] & 0x0F)) << 4 | ((p[-1] & 0x40 ? 9 : 0) + (p[-1] & 0x0F))); 76 | } 77 | 78 | action success { 79 | success = true; 80 | } 81 | 82 | h_space = [ \t]; 83 | identifier = (alpha | digit | '_')+; 84 | 85 | array_index = '[' . digit+ . ']'; 86 | attribute_name = (identifier . array_index?) >attrNameStart %attrNameEnd; 87 | escape_hex = 'x' . xdigit{2}; 88 | escape_seq = '\\' . (escape_hex %attrQuotedValueEscapedHex | [\\"] %attrQuotedValueEscapedChar); 89 | quoted_raw_chars = (print - [\\"])+ >attrQuotedValueRawStart %attrQuotedValueRawEnd; 90 | quoted_value = '"' . ('' | (quoted_raw_chars | escape_seq)**) . '"'; 91 | bare_value = (print - ["])+ >attrBareValueStart %attrBareValueEnd; 92 | value = ((quoted_value . h_space*) | bare_value) >attrValueStart %attrValueEnd; 93 | 94 | attribute = (attribute_name . ':' . h_space+ . value . [\r\n]); 95 | 96 | unit_class = identifier >unitClassStart %unitClassEnd; 97 | unit_instance_name = (identifier . ('.' identifier)*) >unitInstanceStart %unitInstanceEnd; 98 | unit_head = (unit_class . h_space+ . ':' . h_space+ . unit_instance_name . h_space+ . '{') %unitStart; 99 | unit = unit_head . (space* . attribute)* . space* . '}' %unitEnd; 100 | 101 | wrapper = "SiiNunit" . space+ . '{' . (space* . unit . space*)+ . '}' %success; 102 | 103 | file = wrapper . space*; 104 | }%% -------------------------------------------------------------------------------- /lib/rapidjson/filewritestream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_FILEWRITESTREAM_H_ 16 | #define RAPIDJSON_FILEWRITESTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(unreachable-code) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of C file stream for output using fwrite(). 29 | /*! 30 | \note implements Stream concept 31 | */ 32 | class FileWriteStream { 33 | public: 34 | typedef char Ch; //!< Character type. Only support char. 35 | 36 | FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) { 37 | RAPIDJSON_ASSERT(fp_ != 0); 38 | } 39 | 40 | void Put(char c) { 41 | if (current_ >= bufferEnd_) 42 | Flush(); 43 | 44 | *current_++ = c; 45 | } 46 | 47 | void PutN(char c, size_t n) { 48 | size_t avail = static_cast(bufferEnd_ - current_); 49 | while (n > avail) { 50 | std::memset(current_, c, avail); 51 | current_ += avail; 52 | Flush(); 53 | n -= avail; 54 | avail = static_cast(bufferEnd_ - current_); 55 | } 56 | 57 | if (n > 0) { 58 | std::memset(current_, c, n); 59 | current_ += n; 60 | } 61 | } 62 | 63 | void Flush() { 64 | if (current_ != buffer_) { 65 | size_t result = std::fwrite(buffer_, 1, static_cast(current_ - buffer_), fp_); 66 | if (result < static_cast(current_ - buffer_)) { 67 | // failure deliberately ignored at this time 68 | // added to avoid warn_unused_result build errors 69 | } 70 | current_ = buffer_; 71 | } 72 | } 73 | 74 | // Not implemented 75 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 76 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 77 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 78 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 79 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 80 | 81 | private: 82 | // Prohibit copy constructor & assignment operator. 83 | FileWriteStream(const FileWriteStream&); 84 | FileWriteStream& operator=(const FileWriteStream&); 85 | 86 | std::FILE* fp_; 87 | char *buffer_; 88 | char *bufferEnd_; 89 | char *current_; 90 | }; 91 | 92 | //! Implement specialized version of PutN() with memset() for better performance. 93 | template<> 94 | inline void PutN(FileWriteStream& stream, char c, size_t n) { 95 | stream.PutN(c, n); 96 | } 97 | 98 | RAPIDJSON_NAMESPACE_END 99 | 100 | #ifdef __clang__ 101 | RAPIDJSON_DIAG_POP 102 | #endif 103 | 104 | #endif // RAPIDJSON_FILESTREAM_H_ 105 | -------------------------------------------------------------------------------- /lib/rapidjson/internal/pow10.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_POW10_ 16 | #define RAPIDJSON_POW10_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Computes integer powers of 10 in double (10.0^n). 24 | /*! This function uses lookup table for fast and accurate results. 25 | \param n non-negative exponent. Must <= 308. 26 | \return 10.0^n 27 | */ 28 | inline double Pow10(int n) { 29 | static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes 30 | 1e+0, 31 | 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20, 32 | 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40, 33 | 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60, 34 | 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80, 35 | 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100, 36 | 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120, 37 | 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140, 38 | 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160, 39 | 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180, 40 | 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200, 41 | 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220, 42 | 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240, 43 | 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260, 44 | 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280, 45 | 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300, 46 | 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308 47 | }; 48 | RAPIDJSON_ASSERT(n >= 0 && n <= 308); 49 | return e[n]; 50 | } 51 | 52 | } // namespace internal 53 | RAPIDJSON_NAMESPACE_END 54 | 55 | #endif // RAPIDJSON_POW10_ 56 | -------------------------------------------------------------------------------- /lib/rapidjson/error/en.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_ERROR_EN_H_ 16 | #define RAPIDJSON_ERROR_EN_H_ 17 | 18 | #include "error.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(switch-enum) 23 | RAPIDJSON_DIAG_OFF(covered-switch-default) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Maps error code of parsing into error message. 29 | /*! 30 | \ingroup RAPIDJSON_ERRORS 31 | \param parseErrorCode Error code obtained in parsing. 32 | \return the error message. 33 | \note User can make a copy of this function for localization. 34 | Using switch-case is safer for future modification of error codes. 35 | */ 36 | inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) { 37 | switch (parseErrorCode) { 38 | case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error."); 39 | 40 | case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty."); 41 | case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values."); 42 | 43 | case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value."); 44 | 45 | case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member."); 46 | case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member."); 47 | case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member."); 48 | 49 | case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element."); 50 | 51 | case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string."); 52 | case kParseErrorStringUnicodeSurrogateInvalid: return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid."); 53 | case kParseErrorStringEscapeInvalid: return RAPIDJSON_ERROR_STRING("Invalid escape character in string."); 54 | case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string."); 55 | case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoding in string."); 56 | 57 | case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double."); 58 | case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number."); 59 | case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number."); 60 | 61 | case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error."); 62 | case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error."); 63 | 64 | default: return RAPIDJSON_ERROR_STRING("Unknown error."); 65 | } 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #ifdef __clang__ 71 | RAPIDJSON_DIAG_POP 72 | #endif 73 | 74 | #endif // RAPIDJSON_ERROR_EN_H_ 75 | -------------------------------------------------------------------------------- /lib/rapidjson/istreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_ISTREAMWRAPPER_H_ 16 | #define RAPIDJSON_ISTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | #ifdef _MSC_VER 27 | RAPIDJSON_DIAG_PUSH 28 | RAPIDJSON_DIAG_OFF(4351) // new behavior: elements of array 'array' will be default initialized 29 | #endif 30 | 31 | RAPIDJSON_NAMESPACE_BEGIN 32 | 33 | //! Wrapper of \c std::basic_istream into RapidJSON's Stream concept. 34 | /*! 35 | The classes can be wrapped including but not limited to: 36 | 37 | - \c std::istringstream 38 | - \c std::stringstream 39 | - \c std::wistringstream 40 | - \c std::wstringstream 41 | - \c std::ifstream 42 | - \c std::fstream 43 | - \c std::wifstream 44 | - \c std::wfstream 45 | 46 | \tparam StreamType Class derived from \c std::basic_istream. 47 | */ 48 | 49 | template 50 | class BasicIStreamWrapper { 51 | public: 52 | typedef typename StreamType::char_type Ch; 53 | BasicIStreamWrapper(StreamType& stream) : stream_(stream), count_(), peekBuffer_() {} 54 | 55 | Ch Peek() const { 56 | typename StreamType::int_type c = stream_.peek(); 57 | return RAPIDJSON_LIKELY(c != StreamType::traits_type::eof()) ? static_cast(c) : static_cast('\0'); 58 | } 59 | 60 | Ch Take() { 61 | typename StreamType::int_type c = stream_.get(); 62 | if (RAPIDJSON_LIKELY(c != StreamType::traits_type::eof())) { 63 | count_++; 64 | return static_cast(c); 65 | } 66 | else 67 | return '\0'; 68 | } 69 | 70 | // tellg() may return -1 when failed. So we count by ourself. 71 | size_t Tell() const { return count_; } 72 | 73 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 74 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 75 | void Flush() { RAPIDJSON_ASSERT(false); } 76 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 77 | 78 | // For encoding detection only. 79 | const Ch* Peek4() const { 80 | RAPIDJSON_ASSERT(sizeof(Ch) == 1); // Only usable for byte stream. 81 | int i; 82 | bool hasError = false; 83 | for (i = 0; i < 4; ++i) { 84 | typename StreamType::int_type c = stream_.get(); 85 | if (c == StreamType::traits_type::eof()) { 86 | hasError = true; 87 | stream_.clear(); 88 | break; 89 | } 90 | peekBuffer_[i] = static_cast(c); 91 | } 92 | for (--i; i >= 0; --i) 93 | stream_.putback(peekBuffer_[i]); 94 | return !hasError ? peekBuffer_ : 0; 95 | } 96 | 97 | private: 98 | BasicIStreamWrapper(const BasicIStreamWrapper&); 99 | BasicIStreamWrapper& operator=(const BasicIStreamWrapper&); 100 | 101 | StreamType& stream_; 102 | size_t count_; //!< Number of characters read. Note: 103 | mutable Ch peekBuffer_[4]; 104 | }; 105 | 106 | typedef BasicIStreamWrapper IStreamWrapper; 107 | typedef BasicIStreamWrapper WIStreamWrapper; 108 | 109 | #if defined(__clang__) || defined(_MSC_VER) 110 | RAPIDJSON_DIAG_POP 111 | #endif 112 | 113 | RAPIDJSON_NAMESPACE_END 114 | 115 | #endif // RAPIDJSON_ISTREAMWRAPPER_H_ 116 | -------------------------------------------------------------------------------- /lib/rapidjson/stringbuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_STRINGBUFFER_H_ 16 | #define RAPIDJSON_STRINGBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 22 | #include // std::move 23 | #endif 24 | 25 | #include "internal/stack.h" 26 | 27 | #if defined(__clang__) 28 | RAPIDJSON_DIAG_PUSH 29 | RAPIDJSON_DIAG_OFF(c++98-compat) 30 | #endif 31 | 32 | RAPIDJSON_NAMESPACE_BEGIN 33 | 34 | //! Represents an in-memory output stream. 35 | /*! 36 | \tparam Encoding Encoding of the stream. 37 | \tparam Allocator type for allocating memory buffer. 38 | \note implements Stream concept 39 | */ 40 | template 41 | class GenericStringBuffer { 42 | public: 43 | typedef typename Encoding::Ch Ch; 44 | 45 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 46 | 47 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 48 | GenericStringBuffer(GenericStringBuffer&& rhs) : stack_(std::move(rhs.stack_)) {} 49 | GenericStringBuffer& operator=(GenericStringBuffer&& rhs) { 50 | if (&rhs != this) 51 | stack_ = std::move(rhs.stack_); 52 | return *this; 53 | } 54 | #endif 55 | 56 | void Put(Ch c) { *stack_.template Push() = c; } 57 | void PutUnsafe(Ch c) { *stack_.template PushUnsafe() = c; } 58 | void Flush() {} 59 | 60 | void Clear() { stack_.Clear(); } 61 | void ShrinkToFit() { 62 | // Push and pop a null terminator. This is safe. 63 | *stack_.template Push() = '\0'; 64 | stack_.ShrinkToFit(); 65 | stack_.template Pop(1); 66 | } 67 | 68 | void Reserve(size_t count) { stack_.template Reserve(count); } 69 | Ch* Push(size_t count) { return stack_.template Push(count); } 70 | Ch* PushUnsafe(size_t count) { return stack_.template PushUnsafe(count); } 71 | void Pop(size_t count) { stack_.template Pop(count); } 72 | 73 | const Ch* GetString() const { 74 | // Push and pop a null terminator. This is safe. 75 | *stack_.template Push() = '\0'; 76 | stack_.template Pop(1); 77 | 78 | return stack_.template Bottom(); 79 | } 80 | 81 | //! Get the size of string in bytes in the string buffer. 82 | size_t GetSize() const { return stack_.GetSize(); } 83 | 84 | //! Get the length of string in Ch in the string buffer. 85 | size_t GetLength() const { return stack_.GetSize() / sizeof(Ch); } 86 | 87 | static const size_t kDefaultCapacity = 256; 88 | mutable internal::Stack stack_; 89 | 90 | private: 91 | // Prohibit copy constructor & assignment operator. 92 | GenericStringBuffer(const GenericStringBuffer&); 93 | GenericStringBuffer& operator=(const GenericStringBuffer&); 94 | }; 95 | 96 | //! String buffer with UTF8 encoding 97 | typedef GenericStringBuffer > StringBuffer; 98 | 99 | template 100 | inline void PutReserve(GenericStringBuffer& stream, size_t count) { 101 | stream.Reserve(count); 102 | } 103 | 104 | template 105 | inline void PutUnsafe(GenericStringBuffer& stream, typename Encoding::Ch c) { 106 | stream.PutUnsafe(c); 107 | } 108 | 109 | //! Implement specialized version of PutN() with memset() for better performance. 110 | template<> 111 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { 112 | std::memset(stream.stack_.Push(n), c, n * sizeof(c)); 113 | } 114 | 115 | RAPIDJSON_NAMESPACE_END 116 | 117 | #if defined(__clang__) 118 | RAPIDJSON_DIAG_POP 119 | #endif 120 | 121 | #endif // RAPIDJSON_STRINGBUFFER_H_ 122 | -------------------------------------------------------------------------------- /lib/rapidjson/fwd.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_FWD_H_ 16 | #define RAPIDJSON_FWD_H_ 17 | 18 | #include "rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | 22 | // encodings.h 23 | 24 | template struct UTF8; 25 | template struct UTF16; 26 | template struct UTF16BE; 27 | template struct UTF16LE; 28 | template struct UTF32; 29 | template struct UTF32BE; 30 | template struct UTF32LE; 31 | template struct ASCII; 32 | template struct AutoUTF; 33 | 34 | template 35 | struct Transcoder; 36 | 37 | // allocators.h 38 | 39 | class CrtAllocator; 40 | 41 | template 42 | class MemoryPoolAllocator; 43 | 44 | // stream.h 45 | 46 | template 47 | struct GenericStringStream; 48 | 49 | typedef GenericStringStream > StringStream; 50 | 51 | template 52 | struct GenericInsituStringStream; 53 | 54 | typedef GenericInsituStringStream > InsituStringStream; 55 | 56 | // stringbuffer.h 57 | 58 | template 59 | class GenericStringBuffer; 60 | 61 | typedef GenericStringBuffer, CrtAllocator> StringBuffer; 62 | 63 | // filereadstream.h 64 | 65 | class FileReadStream; 66 | 67 | // filewritestream.h 68 | 69 | class FileWriteStream; 70 | 71 | // memorybuffer.h 72 | 73 | template 74 | struct GenericMemoryBuffer; 75 | 76 | typedef GenericMemoryBuffer MemoryBuffer; 77 | 78 | // memorystream.h 79 | 80 | struct MemoryStream; 81 | 82 | // reader.h 83 | 84 | template 85 | struct BaseReaderHandler; 86 | 87 | template 88 | class GenericReader; 89 | 90 | typedef GenericReader, UTF8, CrtAllocator> Reader; 91 | 92 | // writer.h 93 | 94 | template 95 | class Writer; 96 | 97 | // prettywriter.h 98 | 99 | template 100 | class PrettyWriter; 101 | 102 | // document.h 103 | 104 | template 105 | struct GenericMember; 106 | 107 | template 108 | class GenericMemberIterator; 109 | 110 | template 111 | struct GenericStringRef; 112 | 113 | template 114 | class GenericValue; 115 | 116 | typedef GenericValue, MemoryPoolAllocator > Value; 117 | 118 | template 119 | class GenericDocument; 120 | 121 | typedef GenericDocument, MemoryPoolAllocator, CrtAllocator> Document; 122 | 123 | // pointer.h 124 | 125 | template 126 | class GenericPointer; 127 | 128 | typedef GenericPointer Pointer; 129 | 130 | // schema.h 131 | 132 | template 133 | class IGenericRemoteSchemaDocumentProvider; 134 | 135 | template 136 | class GenericSchemaDocument; 137 | 138 | typedef GenericSchemaDocument SchemaDocument; 139 | typedef IGenericRemoteSchemaDocumentProvider IRemoteSchemaDocumentProvider; 140 | 141 | template < 142 | typename SchemaDocumentType, 143 | typename OutputHandler, 144 | typename StateAllocator> 145 | class GenericSchemaValidator; 146 | 147 | typedef GenericSchemaValidator, void>, CrtAllocator> SchemaValidator; 148 | 149 | RAPIDJSON_NAMESPACE_END 150 | 151 | #endif // RAPIDJSON_RAPIDJSONFWD_H_ 152 | -------------------------------------------------------------------------------- /src/DlcSelector.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "DlcSelector.hpp" 3 | 4 | DlcSelector::DlcSelector(wxWindow * parent, wxWindowID id) 5 | : Ets2StaticBox(parent, id, "DLCs") { 6 | wxBoxSizer * contentSizer = getContentSizer(); 7 | 8 | wxBoxSizer * controlsSizer = new wxBoxSizer(wxHORIZONTAL); 9 | contentSizer->Add(controlsSizer, wxSizerFlags().Expand()); 10 | controlsSizer->Add(new wxStaticText(this, wxID_ANY, "Also include jobs that require:")); 11 | controlsSizer->AddStretchSpacer(); 12 | mSelectAll = new wxHyperlinkCtrl(this, wxID_ANY, "Select all", wxEmptyString); 13 | mSelectAll->Bind(wxEVT_HYPERLINK, [this](wxCommandEvent&) { onSelectAll(); }); 14 | controlsSizer->Add(mSelectAll); 15 | 16 | contentSizer->AddSpacer(wxDLG_UNIT(this, wxPoint(0, 7)).y); 17 | 18 | wxCheckBox * cb; 19 | std::vector* vec = &mCheckboxesByGame[Ets2::Game::ETS2]; 20 | cb = new wxCheckBox(this, wxID_ANY, "Scandinavia"); 21 | vec->push_back(cb); 22 | mDlcByCheckbox[cb] = L"north"; 23 | 24 | cb = new wxCheckBox(this, wxID_ANY, "Going East!"); 25 | vec->push_back(cb); 26 | mDlcByCheckbox[cb] = L"east"; 27 | 28 | cb = new wxCheckBox(this, wxID_ANY, "Vive la France!"); 29 | vec->push_back(cb); 30 | mDlcByCheckbox[cb] = L"fr"; 31 | 32 | cb = new wxCheckBox(this, wxID_ANY, "Italia"); 33 | vec->push_back(cb); 34 | mDlcByCheckbox[cb] = L"it"; 35 | 36 | cb = new wxCheckBox(this, wxID_ANY, "High Power Cargo Pack"); 37 | vec->push_back(cb); 38 | mDlcByCheckbox[cb] = L"trailers"; 39 | 40 | cb = new wxCheckBox(this, wxID_ANY, "Heavy Cargo Pack"); 41 | vec->push_back(cb); 42 | mDlcByCheckbox[cb] = L"heavy_cargo"; 43 | 44 | cb = new wxCheckBox(this, wxID_ANY, "Beyond the Baltic Sea"); 45 | vec->push_back(cb); 46 | mDlcByCheckbox[cb] = L"balt"; 47 | 48 | cb = new wxCheckBox(this, wxID_ANY, "Road to the Black Sea"); 49 | vec->push_back(cb); 50 | mDlcByCheckbox[cb] = L"balkane"; 51 | 52 | cb = new wxCheckBox(this, wxID_ANY, "Iberia"); 53 | vec->push_back(cb); 54 | mDlcByCheckbox[cb] = L"iberia"; 55 | 56 | cb = new wxCheckBox(this, wxID_ANY, "Heart of Russia"); 57 | vec->push_back(cb); 58 | mDlcByCheckbox[cb] = L"?"; 59 | 60 | vec = &mCheckboxesByGame[Ets2::Game::ATS]; 61 | cb = new wxCheckBox(this, wxID_ANY, "New Mexico"); 62 | vec->push_back(cb); 63 | mDlcByCheckbox[cb] = L"nwmexico"; 64 | 65 | cb = new wxCheckBox(this, wxID_ANY, "Oregon"); 66 | vec->push_back(cb); 67 | mDlcByCheckbox[cb] = L"oregon"; 68 | 69 | cb = new wxCheckBox(this, wxID_ANY, "Washington"); 70 | vec->push_back(cb); 71 | mDlcByCheckbox[cb] = L"wa"; 72 | 73 | cb = new wxCheckBox(this, wxID_ANY, "Heavy Cargo Pack"); 74 | vec->push_back(cb); 75 | mDlcByCheckbox[cb] = L"heavy"; 76 | 77 | cb = new wxCheckBox(this, wxID_ANY, "Forest Machinery"); 78 | vec->push_back(cb); 79 | mDlcByCheckbox[cb] = L"forest"; 80 | 81 | cb = new wxCheckBox(this, wxID_ANY, "Utah"); 82 | vec->push_back(cb); 83 | mDlcByCheckbox[cb] = L"utah"; 84 | 85 | cb = new wxCheckBox(this, wxID_ANY, "Idaho"); 86 | vec->push_back(cb); 87 | mDlcByCheckbox[cb] = L"idaho"; 88 | 89 | cb = new wxCheckBox(this, wxID_ANY, "Colorado"); 90 | vec->push_back(cb); 91 | mDlcByCheckbox[cb] = L"colorado"; 92 | 93 | cb = new wxCheckBox(this, wxID_ANY, "Wyoming"); 94 | vec->push_back(cb); 95 | mDlcByCheckbox[cb] = L"?"; 96 | 97 | cb = new wxCheckBox(this, wxID_ANY, "Texas"); 98 | vec->push_back(cb); 99 | mDlcByCheckbox[cb] = L"?"; 100 | 101 | wxBoxSizer * parentSizer = new wxBoxSizer(wxHORIZONTAL); 102 | contentSizer->Add(parentSizer, wxSizerFlags().Expand()); 103 | for (size_t i = 0; i < std::max(mCheckboxesByGame[Ets2::Game::ETS2].size(), mCheckboxesByGame[Ets2::Game::ATS].size()); i++) { 104 | if ((i % 5) == 0) { 105 | if (i > 0) { 106 | parentSizer->AddStretchSpacer(1); 107 | } 108 | 109 | controlsSizer = new wxBoxSizer(wxVERTICAL); 110 | parentSizer->Add(controlsSizer, wxSizerFlags().Proportion(2)); 111 | } else { 112 | controlsSizer->AddSpacer(wxDLG_UNIT(this, wxPoint(0, 4)).y); 113 | } 114 | for (auto& m : mCheckboxesByGame) { 115 | if (i < m.second.size()) { 116 | controlsSizer->Add(m.second[i]); 117 | } 118 | } 119 | } 120 | 121 | setSave(nullptr); 122 | 123 | parentSizer->AddStretchSpacer(1); 124 | } 125 | 126 | void DlcSelector::setSave(const Ets2::Save * save) { 127 | mSave = save; 128 | const Ets2::Save::DlcList * dlcs = nullptr; 129 | Ets2::Game game = Ets2::Game::ETS2; 130 | if (mSave != nullptr) { 131 | game = mSave->getGame(); 132 | dlcs = &(mSave->getDlcs()); 133 | } 134 | 135 | bool present = false; 136 | for (auto& m : mCheckboxesByGame) { 137 | for (auto& cb : m.second) { 138 | cb->Show(m.first == game); 139 | present = (dlcs != nullptr) && (m.first == game ? (std::find(dlcs->begin(), dlcs->end(), mDlcByCheckbox[cb]) != dlcs->end()) : false); 140 | if (present && cb->GetLabelText().compare("?") != 0) { 141 | cb->Enable(); 142 | } else { 143 | cb->SetValue(false); 144 | cb->Disable(); 145 | } 146 | } 147 | } 148 | Layout(); 149 | } 150 | 151 | const Ets2::Save::DlcList DlcSelector::getDlcs() const { 152 | Ets2::Save::DlcList dlcs = {}; 153 | if (mSave == nullptr) { 154 | return dlcs; 155 | } 156 | 157 | for (auto& cb : mCheckboxesByGame.at(mSave->getGame())) { 158 | if (cb->IsEnabled() && cb->IsChecked()) { 159 | dlcs.push_back(mDlcByCheckbox.at(cb)); 160 | } 161 | } 162 | return dlcs; 163 | } 164 | 165 | void DlcSelector::onSelectAll() { 166 | Ets2::Game game = (mSave == nullptr ? Ets2::Game::ETS2 : mSave->getGame()); 167 | bool clear = false; 168 | 169 | for (auto& cb : mCheckboxesByGame[game]) { 170 | if (cb->IsChecked()) { 171 | clear = true; 172 | break; 173 | } 174 | } 175 | 176 | for (auto& cb : mCheckboxesByGame[game]) { 177 | if (cb->IsEnabled()) { 178 | cb->SetValue(!clear); 179 | } 180 | } 181 | } -------------------------------------------------------------------------------- /README-fr.md: -------------------------------------------------------------------------------- 1 | # ETS2&ATS Sync Helper 2 | 3 | ![Github All Releases](https://img.shields.io/github/downloads/Inklay/ETS2-ATS-Sync-Helper/total.svg) 4 | ![ETS2 Version](https://img.shields.io/badge/ETS2%20Version-1.39%20%2B-green) 5 | ![ETS2 DLC](https://img.shields.io/badge/ETS%20DLC-ALL-yellowgreen) 6 | ![ATS Version](https://img.shields.io/badge/ATS%20Version-1.39%20%2B-green) 7 | ![ATS DLC](https://img.shields.io/badge/ATS%20DLC-ALL-yellowgreen) 8 | * [English version](README.md) 9 | 10 | [LICENSE](LICENSE.md) 11 | 12 | * [Téléchargement](#téléchargement) 13 | * [Installation](#installation-up) 14 | * [Synchroniser](#synchroniser) 15 | * [Fontionnalités](#fontionnalités) 16 | * [Supprimer les missions](#supprimer-les-missions) 17 | * [Remise à 0 de l'économie](#remise-à-0-de-l'économie) 18 | * [Liste de mission](#liste-de-mission) 19 | * [Erreurs communes](#erreurs-communes) 20 | * [Bugs](#bugs) 21 | 22 | Ce programme a été entièrement réécrit en C++ par David Santos, je m'occupe de maintenir le programme a jour en supportant les dernières mises à jour des jeux et les DLCs. 23 | 24 | Ce programme syncronise votre liste de travails sur Euro Truck Simulator 2 et Americain Truck Simulator pour faciliter l'organisationb de convoi en multijoueur. 25 | 26 | A l'heure actuelle, le programme ne fonctionne qu'en anglais. D'autres langues peuvent être ajoutées par la suite. 27 | 28 | ## Téléchargement 29 | https://github.com/Inklay/ETS2-ATS-Sync-Helper/releases 30 | 31 | ## Installation 32 | Lancez ETS2Sync Helper et selectionnez votre jeu (ETS2 ou ATS). Regardez l'onglet “Game Settings”. S'il y a un message vert disant “Settings OK”, tout est bon. Si le message est orange ou rouge vous devez suivre ces étapes: 33 | 1. Fermez le jeu. Ca ne marchera pas si le jeu reste ouvert. 34 | 2. Dans ETS2Sync Helper, dans l'onglet “Game Settings”, dans “Save Format”, clickez sur “Set to ‘Text’”. Le message rouge ou orange devrait devenir vert et dire “Settings OK”. ET c'est bon ! Votre jeu est prêt pour être syncronisé, vous pouvez aller à [Synchroniser](#how-to-sync). 35 | 36 | 37 | ## Synchroniser 38 | 1. Allez à l'écran d'accueil (si vous conduisez, appuyez sur Esc). 39 | 2. Clickez sur “Sauver & charger” → “Enregistrer la partie”. 40 | 3. Entrez un nom pour la sauvegarde ou sélectionnez en une déjà existante et écrasez là. 41 | 4. Clickez sur “Enregistrer”. 42 | 5. Faites `Alt`+`Tab` pour réduir le jeu. 43 | 6. Ouvrez ETS2Sync Helper s'il ne l'était pas déjà. Selectionnez le bon jeu dans l'option “Game” de l'onglet “Game Settings”. 44 | 7. Sélectionnez le bon profile et la bonne sauvegarde dans “Select ETS2/ATS Profile” et “Select ETS2/ATS Save”. 45 | 8. Sélectionnez les DLCs que vous et vos amis possédez (ne sélectionnez un DLC que si tout le monde l'a). 46 | 9. Clickez sur “Sync Jobs”. 47 | 10. Lorsque le message “Sync Complete” apparait, clickez sur “Close”. 48 | 11. Retournez dans le jeu. 49 | 12. Clickez sur “Sauver & charger” → “Charger une partie”. 50 | 13. Sélectionnez la sauvegarde que vous venez de syncroniser (celle que vous avez créée/remplacée à l'étape 4). 51 | 14. Clickez sur Charger. 52 | 15. Allez dans les offres de traction ou les offres de fret. Si toutes les missions ont la même date d'expiration (“l'offre expire dans”), et que cette date est d'environ 400 ou 500 heures, alors la synchronisation a bien marché. 53 | 54 | ## Fontionnalités 55 | ### Supprimer les missions 56 | Cette fonctionnalité vous donne la possibilité de supprimer toutes vos missions. Si vous avez terminé de jouer avec les listes de missions synchronisées et que vous voulez générer de nouvelles missions pour jouer en solo, vous avez juste à suivre les mêmes étapes que pour synchroniser, mais vous dever clicker sur “Clear Jobs” au lieu de “Sync Jobs”. Lorsque vous chargerez la sauvegarde, le marché du travail sera vide. Appelez un dépanneur (F7) ou utilisez l'option de voyage rapide pour générer de nouvelles missions. 57 | 58 | ### Remise à 0 de l'économie 59 | Cette fonctionnalité foncitonne comme "Supprimer les missions", mais elle est plus rapide car lorsque vous chargerez la sauvegarde vous aurez un message disant “Changements dans le jeu détectés”, qui va directement générer de nouvelles missions (vous n'avez donc pas besoin de vous déplacez ou d'appeler une dépaneuse pour avoir de nouvelles missions). Cependant cette methode vous téléportera toujours à votre garage principal. 60 | 61 | ### Liste de mission 62 | Lors de la synchronisation, le programme télécharge une liste de mission et l'injecte dans votre sauvegarde. Il y a 8 listes pour ATS et ETS2 sur le serveur. Une de ces 8 listes sera utilisée si vous laissez l'option “Job List” sur “Automatic”. Chaque jours cette liste change (Si la liste du jour est la 7, le lendemain ça sera la 8). 63 | 64 | Les listes de missions ne changent pas, sauf si le jeu ou les DLCs le nécessitent (Une mise à jour du jeu ou d'un DLC ou un nouveau DLC). Si vous ne voulez pas qu' votre liste de mission change d'un jour à l'autre, vous avez juste à toujours selectionner la même dans l'option “Job List”. 65 | 66 | ## Erreurs communes 67 | 68 | ### Les sauvegardes en format binaires ne sont pas supportées, veuillez créer vos sauvegarde en format text 69 | Si vous sélectionnez une ancienne sauvegarde ou que votre jeu est mal configuré. 70 | * Si ETS2Sync Helper n'affiche pas un message vert disant “Settings OK” dans l'onglet “Game Settings”, vous devez faire les étapes décrire dans la section[Installation](#setting-up). 71 | * Si le message “Settings OK” étair déjà affiché, vérifiez que vous avez sélectionné le bon profile et la bonne sauvegarde. 72 | * SI ça ne marche toujours pas, fermez ETS2Sync Helper et le jeu, ensuite rouvrez ETS2Sync Helper et regardez si le message vert dit toujours “Settings OK”. Si ce n'est pas le cas lisez les instructions ci-dessus. Si c'est le cas, ouvrez le jeu et créez une nouvelle sauvegarde avant de synchroniser. 73 | 74 | ### Could not download the job list. InternetOpenURL error 75 | ### Could not download the job list. HTTP 500 Internal Server Error 76 | ### Could not download the job list. HTTP 401 Unauthorized 77 | ### Could not download the job list. HTTP 403 Forbidden 78 | ### Could not download the job list. HTTP 404 Not Found 79 | Il y a très certainement un problème avec le serveur ou votre connection internet, si votre connection fonctionne correctement, attendez quelques minutes et réessayer. 80 | 81 | ## Bugs 82 | Si vous recontrer une erreur ou un bug, merci de le reporter ici: 83 | 84 | https://github.com/Inklay/ETS2-ATS-Sync-Helper/issues 85 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | src/Ets2/Parser/*svg 2 | src/Ets2/Parser/SiiText.cpp 3 | src/Ets2/Parser/Cfg.cpp 4 | 5 | ## Ignore Visual Studio temporary files, build results, and 6 | ## files generated by popular Visual Studio add-ons. 7 | 8 | # User-specific files 9 | *.suo 10 | *.user 11 | *.userosscache 12 | *.sln.docstates 13 | 14 | # User-specific files (MonoDevelop/Xamarin Studio) 15 | *.userprefs 16 | 17 | # Build results 18 | [Dd]ebug/ 19 | [Dd]ebugPublic/ 20 | [Rr]elease/ 21 | [Rr]eleases/ 22 | x64/ 23 | x86/ 24 | bld/ 25 | [Bb]in/ 26 | [Oo]bj/ 27 | [Ll]og/ 28 | 29 | # Visual Studio 2015 cache/options directory 30 | .vs/ 31 | # Uncomment if you have tasks that create the project's static files in wwwroot 32 | #wwwroot/ 33 | 34 | # MSTest test Results 35 | [Tt]est[Rr]esult*/ 36 | [Bb]uild[Ll]og.* 37 | 38 | # NUNIT 39 | *.VisualState.xml 40 | TestResult.xml 41 | 42 | # Build Results of an ATL Project 43 | [Dd]ebugPS/ 44 | [Rr]eleasePS/ 45 | dlldata.c 46 | 47 | # DNX 48 | project.lock.json 49 | artifacts/ 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # NCrunch 117 | _NCrunch_* 118 | .*crunch*.local.xml 119 | nCrunchTemp_* 120 | 121 | # MightyMoose 122 | *.mm.* 123 | AutoTest.Net/ 124 | 125 | # Web workbench (sass) 126 | .sass-cache/ 127 | 128 | # Installshield output folder 129 | [Ee]xpress/ 130 | 131 | # DocProject is a documentation generator add-in 132 | DocProject/buildhelp/ 133 | DocProject/Help/*.HxT 134 | DocProject/Help/*.HxC 135 | DocProject/Help/*.hhc 136 | DocProject/Help/*.hhk 137 | DocProject/Help/*.hhp 138 | DocProject/Help/Html2 139 | DocProject/Help/html 140 | 141 | # Click-Once directory 142 | publish/ 143 | 144 | # Publish Web Output 145 | *.[Pp]ublish.xml 146 | *.azurePubxml 147 | # TODO: Comment the next line if you want to checkin your web deploy settings 148 | # but database connection strings (with potential passwords) will be unencrypted 149 | *.pubxml 150 | *.publishproj 151 | 152 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 153 | # checkin your Azure Web App publish settings, but sensitive information contained 154 | # in these scripts will be unencrypted 155 | PublishScripts/ 156 | 157 | # NuGet Packages 158 | *.nupkg 159 | # The packages folder can be ignored because of Package Restore 160 | **/packages/* 161 | # except build/, which is used as an MSBuild target. 162 | !**/packages/build/ 163 | # Uncomment if necessary however generally it will be regenerated when needed 164 | #!**/packages/repositories.config 165 | # NuGet v3's project.json files produces more ignoreable files 166 | *.nuget.props 167 | *.nuget.targets 168 | 169 | # Microsoft Azure Build Output 170 | csx/ 171 | *.build.csdef 172 | 173 | # Microsoft Azure Emulator 174 | ecf/ 175 | rcf/ 176 | 177 | # Windows Store app package directories and files 178 | AppPackages/ 179 | BundleArtifacts/ 180 | Package.StoreAssociation.xml 181 | _pkginfo.txt 182 | 183 | # Visual Studio cache files 184 | # files ending in .cache can be ignored 185 | *.[Cc]ache 186 | # but keep track of directories ending in .cache 187 | !*.[Cc]ache/ 188 | 189 | # Others 190 | ClientBin/ 191 | ~$* 192 | *~ 193 | *.dbmdl 194 | *.dbproj.schemaview 195 | *.pfx 196 | *.publishsettings 197 | node_modules/ 198 | orleans.codegen.cs 199 | 200 | # Since there are multiple workflows, uncomment next line to ignore bower_components 201 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 202 | #bower_components/ 203 | 204 | # RIA/Silverlight projects 205 | Generated_Code/ 206 | 207 | # Backup & report files from converting an old project file 208 | # to a newer Visual Studio version. Backup files are not needed, 209 | # because we have git ;-) 210 | _UpgradeReport_Files/ 211 | Backup*/ 212 | UpgradeLog*.XML 213 | UpgradeLog*.htm 214 | 215 | # SQL Server files 216 | *.mdf 217 | *.ldf 218 | 219 | # Business Intelligence projects 220 | *.rdl.data 221 | *.bim.layout 222 | *.bim_*.settings 223 | 224 | # Microsoft Fakes 225 | FakesAssemblies/ 226 | 227 | # GhostDoc plugin setting file 228 | *.GhostDoc.xml 229 | 230 | # Node.js Tools for Visual Studio 231 | .ntvs_analysis.dat 232 | 233 | # Visual Studio 6 build log 234 | *.plg 235 | 236 | # Visual Studio 6 workspace options file 237 | *.opt 238 | 239 | # Visual Studio LightSwitch build output 240 | **/*.HTMLClient/GeneratedArtifacts 241 | **/*.DesktopClient/GeneratedArtifacts 242 | **/*.DesktopClient/ModelManifest.xml 243 | **/*.Server/GeneratedArtifacts 244 | **/*.Server/ModelManifest.xml 245 | _Pvt_Extensions 246 | 247 | # Paket dependency manager 248 | .paket/paket.exe 249 | paket-files/ 250 | 251 | # FAKE - F# Make 252 | .fake/ 253 | 254 | # JetBrains Rider 255 | .idea/ 256 | *.sln.iml 257 | 258 | # ========================= 259 | # Operating System Files 260 | # ========================= 261 | 262 | # OSX 263 | # ========================= 264 | 265 | .DS_Store 266 | .AppleDouble 267 | .LSOverride 268 | 269 | # Thumbnails 270 | ._* 271 | 272 | # Files that might appear in the root of a volume 273 | .DocumentRevisions-V100 274 | .fseventsd 275 | .Spotlight-V100 276 | .TemporaryItems 277 | .Trashes 278 | .VolumeIcon.icns 279 | 280 | # Directories potentially created on remote AFP share 281 | .AppleDB 282 | .AppleDesktop 283 | Network Trash Folder 284 | Temporary Items 285 | .apdisk 286 | 287 | # Windows 288 | # ========================= 289 | 290 | # Windows image file caches 291 | Thumbs.db 292 | ehthumbs.db 293 | 294 | # Folder config file 295 | Desktop.ini 296 | 297 | # Recycle Bin used on file shares 298 | $RECYCLE.BIN/ 299 | 300 | # Windows Installer files 301 | *.cab 302 | *.msi 303 | *.msm 304 | *.msp 305 | 306 | # Windows shortcuts 307 | *.lnk 308 | -------------------------------------------------------------------------------- /src/AboutWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "precomp.hpp" 2 | #include "AboutWindow.hpp" 3 | 4 | #include "version.hpp" 5 | #include "MainWindow.hpp" 6 | 7 | #include 8 | #include 9 | 10 | AboutWindow::AboutWindow(MainWindow * wndParent) 11 | : wxDialog(wndParent, wxID_ANY, "About " + APP_DISPLAY_NAME) { 12 | 13 | SetIcon(GetParent()->GetIcon()); 14 | Bind(wxEVT_SHOW, &AboutWindow::onShow, this); 15 | 16 | wxPoint border = wxDLG_UNIT(this, wxPoint(7, 7)); 17 | wxPoint internalBorder = wxDLG_UNIT(this, wxPoint(4, 4)); 18 | 19 | mUpdateChecker = new UpdateChecker(this); 20 | mUpdateChecker->Bind(EVT_UPDATE_CHECKER, [this](wxCommandEvent&) { onUpdateStatus(); }); 21 | 22 | wxBoxSizer * canvas = new wxBoxSizer(wxHORIZONTAL); 23 | wxBitmap logo("app_logo", wxBITMAP_TYPE_PNG_RESOURCE); 24 | canvas->Add(new wxStaticBitmap(this, wxID_ANY, logo), wxSizerFlags().Border(wxRIGHT, border.x)); 25 | 26 | wxBoxSizer * infoSizer = new wxBoxSizer(wxVERTICAL); 27 | wxStaticText * appName = new wxStaticText(this, wxID_ANY, APP_DISPLAY_NAME); 28 | appName->SetFont(appName->GetFont().Scale(3.0).MakeBold()); 29 | infoSizer->Add(appName); 30 | 31 | wxStaticText * appVersion = new wxStaticText(this, wxID_ANY, "Version " + APP_VERSION); 32 | appVersion->SetFont(appVersion->GetFont().Scale(1.7f).MakeBold()); 33 | infoSizer->Add(appVersion, wxSizerFlags()); 34 | 35 | infoSizer->AddSpacer(internalBorder.y); 36 | 37 | mUpdateCheckSizer = new wxBoxSizer(wxHORIZONTAL); 38 | 39 | mCheckingAnimation = new wxActivityIndicator(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(10, 10))); 40 | mUpdateCheckSizer->Add(mCheckingAnimation, wxSizerFlags().CenterVertical().Proportion(0).Border(wxRIGHT, 5)); 41 | 42 | mCheckStatusText = new StatusText(this, wxID_ANY); 43 | mUpdateCheckSizer->Add(mCheckStatusText, wxSizerFlags().CenterVertical(). Proportion(1)); 44 | 45 | mUpdateCheckSizer->AddSpacer(internalBorder.x); 46 | 47 | mUpdateCheckAgain = new wxButton(this, wxID_ANY, "Stop"); 48 | mUpdateCheckAgain->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {onUpdateCheckAgain(); }); 49 | mUpdateCheckSizer->Add(mUpdateCheckAgain, wxSizerFlags().CenterVertical().Proportion(0)); 50 | 51 | infoSizer->Add(mUpdateCheckSizer, wxSizerFlags().Expand()); 52 | 53 | infoSizer->AddSpacer(internalBorder.y); 54 | 55 | wxBoxSizer * websiteSizer = new wxBoxSizer(wxHORIZONTAL); 56 | websiteSizer->Add(new wxStaticText(this, wxID_ANY, "Github: ")); 57 | websiteSizer->Add(new wxHyperlinkCtrl(this, wxID_ANY, APP_URL_WEBSITE, APP_URL_WEBSITE)); 58 | infoSizer->Add(websiteSizer); 59 | 60 | infoSizer->AddSpacer(border.y); 61 | 62 | wxBoxSizer * creatorSizer = new wxBoxSizer(wxHORIZONTAL); 63 | creatorSizer->Add(new wxStaticText(this, wxID_ANY, "Developesr: ")); 64 | creatorSizer->Add(new wxHyperlinkCtrl(this, wxID_ANY, "Inklay & David Santos", "https://github.com/Inklay/")); 65 | infoSizer->Add(creatorSizer); 66 | 67 | /*wxBoxSizer * jobListSizer = new wxBoxSizer(wxHORIZONTAL); 68 | jobListSizer->Add(new wxStaticText(this, wxID_ANY, "Job List: ")); 69 | jobListSizer->Add(new wxHyperlinkCtrl(this, wxID_ANY, "ETS2 Job Sync", "http://www.ets2sync.com/")); 70 | infoSizer->Add(jobListSizer); 71 | 72 | wxBoxSizer * translatorSizer = new wxBoxSizer(wxHORIZONTAL); 73 | translatorSizer->Add(new wxStaticText(this, wxID_ANY, "English Translation: ")); 74 | translatorSizer->Add(new wxHyperlinkCtrl(this, wxID_ANY, "David Santos", "https://github.com/davidsantos-br/")); 75 | infoSizer->Add(translatorSizer);*/ 76 | 77 | infoSizer->AddSpacer(border.y); 78 | 79 | infoSizer->Add(new wxStaticText(this, wxID_ANY, wxGetLibraryVersionInfo().ToString().Trim())); 80 | 81 | canvas->Add(infoSizer); 82 | 83 | wxBoxSizer * windowSizer = new wxBoxSizer(wxVERTICAL); 84 | windowSizer->AddSpacer(border.y); 85 | windowSizer->Add(canvas, wxSizerFlags().Border(wxLEFT|wxRIGHT, border.x)); 86 | windowSizer->AddSpacer(border.y); 87 | windowSizer->Add(new wxStaticLine(this), wxSizerFlags().Expand()); 88 | windowSizer->AddSpacer(border.y); 89 | 90 | wxBoxSizer * closeSizer = new wxBoxSizer(wxHORIZONTAL); 91 | closeSizer->Add(new wxStaticText(this, wxID_ANY, "Built on " __DATE__ " " __TIME__ " (" 92 | #ifdef _DEBUG 93 | "Debug" 94 | #else 95 | "Release" 96 | #endif 97 | " build)"), wxSizerFlags().CenterVertical()); 98 | closeSizer->AddStretchSpacer(); 99 | wxButton * closeButton = new wxButton(this, wxID_CLOSE, "Close"); 100 | closeSizer->Add(closeButton); 101 | windowSizer->Add(closeSizer, wxSizerFlags().Expand().Border(wxLEFT|wxRIGHT, border.x)); 102 | closeButton->SetFocus(); 103 | closeButton->SetDefault(); 104 | closeButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { Close(); }); 105 | 106 | windowSizer->AddSpacer(border.y); 107 | SetSizerAndFit(windowSizer); 108 | } 109 | 110 | AboutWindow::~AboutWindow() { 111 | delete mUpdateChecker; 112 | } 113 | 114 | MainWindow * AboutWindow::GetParent() { 115 | return static_cast(wxDialog::GetParent()); 116 | } 117 | 118 | void AboutWindow::checkUpdates() { 119 | mUpdateChecker->start(); 120 | } 121 | 122 | void AboutWindow::onUpdateStatus() { 123 | UpdateChecker::Status status = mUpdateChecker->getStatus(); 124 | 125 | StatusText::Type statusTextType; 126 | if (status.state == UpdateChecker::State::RUNNING) { 127 | statusTextType = StatusText::Type::STATUS; 128 | } else if (status.state == UpdateChecker::State::FINISHED && status.result == UpdateChecker::Result::UP_TO_DATE) { 129 | statusTextType = StatusText::Type::SUCCESS; 130 | } else { 131 | statusTextType = StatusText::Type::FAILURE; 132 | } 133 | mCheckStatusText->SetLabel(UpdateChecker::getStatusDescription(status), statusTextType); 134 | if (status.state != UpdateChecker::State::RUNNING) { 135 | if (mCheckingAnimation->IsShown()) { 136 | mCheckingAnimation->Stop(); 137 | mCheckingAnimation->Hide(); 138 | mUpdateCheckAgain->SetLabel("Check Again"); 139 | } 140 | } else { 141 | if (!mCheckingAnimation->IsShown()) { 142 | mCheckingAnimation->Show(); 143 | mCheckingAnimation->Start(); 144 | mUpdateCheckAgain->SetLabel("Stop"); 145 | } 146 | } 147 | mUpdateCheckSizer->Layout(); 148 | } 149 | 150 | void AboutWindow::onShow(wxShowEvent& weEvent) { 151 | if (weEvent.IsShown()) { 152 | Center(); 153 | checkUpdates(); 154 | } 155 | } 156 | 157 | void AboutWindow::onUpdateCheckAgain() { 158 | if (mUpdateChecker->getStatus().state == UpdateChecker::State::RUNNING) { 159 | mUpdateChecker->cancel(); 160 | } else { 161 | checkUpdates(); 162 | } 163 | } 164 | 165 | void AboutWindow::onOpenWebsite() { 166 | GetParent()->openWebsite(); 167 | } 168 | 169 | void AboutWindow::onClose() { 170 | Close(); 171 | } -------------------------------------------------------------------------------- /lib/rapidjson/error/error.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_ERROR_ERROR_H_ 16 | #define RAPIDJSON_ERROR_ERROR_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(padded) 23 | #endif 24 | 25 | /*! \file error.h */ 26 | 27 | /*! \defgroup RAPIDJSON_ERRORS RapidJSON error handling */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // RAPIDJSON_ERROR_CHARTYPE 31 | 32 | //! Character type of error messages. 33 | /*! \ingroup RAPIDJSON_ERRORS 34 | The default character type is \c char. 35 | On Windows, user can define this macro as \c TCHAR for supporting both 36 | unicode/non-unicode settings. 37 | */ 38 | #ifndef RAPIDJSON_ERROR_CHARTYPE 39 | #define RAPIDJSON_ERROR_CHARTYPE char 40 | #endif 41 | 42 | /////////////////////////////////////////////////////////////////////////////// 43 | // RAPIDJSON_ERROR_STRING 44 | 45 | //! Macro for converting string literial to \ref RAPIDJSON_ERROR_CHARTYPE[]. 46 | /*! \ingroup RAPIDJSON_ERRORS 47 | By default this conversion macro does nothing. 48 | On Windows, user can define this macro as \c _T(x) for supporting both 49 | unicode/non-unicode settings. 50 | */ 51 | #ifndef RAPIDJSON_ERROR_STRING 52 | #define RAPIDJSON_ERROR_STRING(x) x 53 | #endif 54 | 55 | RAPIDJSON_NAMESPACE_BEGIN 56 | 57 | /////////////////////////////////////////////////////////////////////////////// 58 | // ParseErrorCode 59 | 60 | //! Error code of parsing. 61 | /*! \ingroup RAPIDJSON_ERRORS 62 | \see GenericReader::Parse, GenericReader::GetParseErrorCode 63 | */ 64 | enum ParseErrorCode { 65 | kParseErrorNone = 0, //!< No error. 66 | 67 | kParseErrorDocumentEmpty, //!< The document is empty. 68 | kParseErrorDocumentRootNotSingular, //!< The document root must not follow by other values. 69 | 70 | kParseErrorValueInvalid, //!< Invalid value. 71 | 72 | kParseErrorObjectMissName, //!< Missing a name for object member. 73 | kParseErrorObjectMissColon, //!< Missing a colon after a name of object member. 74 | kParseErrorObjectMissCommaOrCurlyBracket, //!< Missing a comma or '}' after an object member. 75 | 76 | kParseErrorArrayMissCommaOrSquareBracket, //!< Missing a comma or ']' after an array element. 77 | 78 | kParseErrorStringUnicodeEscapeInvalidHex, //!< Incorrect hex digit after \\u escape in string. 79 | kParseErrorStringUnicodeSurrogateInvalid, //!< The surrogate pair in string is invalid. 80 | kParseErrorStringEscapeInvalid, //!< Invalid escape character in string. 81 | kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark in string. 82 | kParseErrorStringInvalidEncoding, //!< Invalid encoding in string. 83 | 84 | kParseErrorNumberTooBig, //!< Number too big to be stored in double. 85 | kParseErrorNumberMissFraction, //!< Miss fraction part in number. 86 | kParseErrorNumberMissExponent, //!< Miss exponent in number. 87 | 88 | kParseErrorTermination, //!< Parsing was terminated. 89 | kParseErrorUnspecificSyntaxError //!< Unspecific syntax error. 90 | }; 91 | 92 | //! Result of parsing (wraps ParseErrorCode) 93 | /*! 94 | \ingroup RAPIDJSON_ERRORS 95 | \code 96 | Document doc; 97 | ParseResult ok = doc.Parse("[42]"); 98 | if (!ok) { 99 | fprintf(stderr, "JSON parse error: %s (%u)", 100 | GetParseError_En(ok.Code()), ok.Offset()); 101 | exit(EXIT_FAILURE); 102 | } 103 | \endcode 104 | \see GenericReader::Parse, GenericDocument::Parse 105 | */ 106 | struct ParseResult { 107 | //!! Unspecified boolean type 108 | typedef bool (ParseResult::*BooleanType)() const; 109 | public: 110 | //! Default constructor, no error. 111 | ParseResult() : code_(kParseErrorNone), offset_(0) {} 112 | //! Constructor to set an error. 113 | ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {} 114 | 115 | //! Get the error code. 116 | ParseErrorCode Code() const { return code_; } 117 | //! Get the error offset, if \ref IsError(), 0 otherwise. 118 | size_t Offset() const { return offset_; } 119 | 120 | //! Explicit conversion to \c bool, returns \c true, iff !\ref IsError(). 121 | operator BooleanType() const { return !IsError() ? &ParseResult::IsError : NULL; } 122 | //! Whether the result is an error. 123 | bool IsError() const { return code_ != kParseErrorNone; } 124 | 125 | bool operator==(const ParseResult& that) const { return code_ == that.code_; } 126 | bool operator==(ParseErrorCode code) const { return code_ == code; } 127 | friend bool operator==(ParseErrorCode code, const ParseResult & err) { return code == err.code_; } 128 | 129 | bool operator!=(const ParseResult& that) const { return !(*this == that); } 130 | bool operator!=(ParseErrorCode code) const { return !(*this == code); } 131 | friend bool operator!=(ParseErrorCode code, const ParseResult & err) { return err != code; } 132 | 133 | //! Reset error code. 134 | void Clear() { Set(kParseErrorNone); } 135 | //! Update error code and offset. 136 | void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; } 137 | 138 | private: 139 | ParseErrorCode code_; 140 | size_t offset_; 141 | }; 142 | 143 | //! Function pointer type of GetParseError(). 144 | /*! \ingroup RAPIDJSON_ERRORS 145 | 146 | This is the prototype for \c GetParseError_X(), where \c X is a locale. 147 | User can dynamically change locale in runtime, e.g.: 148 | \code 149 | GetParseErrorFunc GetParseError = GetParseError_En; // or whatever 150 | const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode()); 151 | \endcode 152 | */ 153 | typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode); 154 | 155 | RAPIDJSON_NAMESPACE_END 156 | 157 | #ifdef __clang__ 158 | RAPIDJSON_DIAG_POP 159 | #endif 160 | 161 | #endif // RAPIDJSON_ERROR_ERROR_H_ 162 | -------------------------------------------------------------------------------- /lib/rapidjson/internal/meta.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_META_H_ 16 | #define RAPIDJSON_INTERNAL_META_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #ifdef __GNUC__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(effc++) 23 | #endif 24 | #if defined(_MSC_VER) 25 | RAPIDJSON_DIAG_PUSH 26 | RAPIDJSON_DIAG_OFF(6334) 27 | #endif 28 | 29 | #if RAPIDJSON_HAS_CXX11_TYPETRAITS 30 | #include 31 | #endif 32 | 33 | //@cond RAPIDJSON_INTERNAL 34 | RAPIDJSON_NAMESPACE_BEGIN 35 | namespace internal { 36 | 37 | // Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching 38 | template struct Void { typedef void Type; }; 39 | 40 | /////////////////////////////////////////////////////////////////////////////// 41 | // BoolType, TrueType, FalseType 42 | // 43 | template struct BoolType { 44 | static const bool Value = Cond; 45 | typedef BoolType Type; 46 | }; 47 | typedef BoolType TrueType; 48 | typedef BoolType FalseType; 49 | 50 | 51 | /////////////////////////////////////////////////////////////////////////////// 52 | // SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr 53 | // 54 | 55 | template struct SelectIfImpl { template struct Apply { typedef T1 Type; }; }; 56 | template <> struct SelectIfImpl { template struct Apply { typedef T2 Type; }; }; 57 | template struct SelectIfCond : SelectIfImpl::template Apply {}; 58 | template struct SelectIf : SelectIfCond {}; 59 | 60 | template struct AndExprCond : FalseType {}; 61 | template <> struct AndExprCond : TrueType {}; 62 | template struct OrExprCond : TrueType {}; 63 | template <> struct OrExprCond : FalseType {}; 64 | 65 | template struct BoolExpr : SelectIf::Type {}; 66 | template struct NotExpr : SelectIf::Type {}; 67 | template struct AndExpr : AndExprCond::Type {}; 68 | template struct OrExpr : OrExprCond::Type {}; 69 | 70 | 71 | /////////////////////////////////////////////////////////////////////////////// 72 | // AddConst, MaybeAddConst, RemoveConst 73 | template struct AddConst { typedef const T Type; }; 74 | template struct MaybeAddConst : SelectIfCond {}; 75 | template struct RemoveConst { typedef T Type; }; 76 | template struct RemoveConst { typedef T Type; }; 77 | 78 | 79 | /////////////////////////////////////////////////////////////////////////////// 80 | // IsSame, IsConst, IsMoreConst, IsPointer 81 | // 82 | template struct IsSame : FalseType {}; 83 | template struct IsSame : TrueType {}; 84 | 85 | template struct IsConst : FalseType {}; 86 | template struct IsConst : TrueType {}; 87 | 88 | template 89 | struct IsMoreConst 90 | : AndExpr::Type, typename RemoveConst::Type>, 91 | BoolType::Value >= IsConst::Value> >::Type {}; 92 | 93 | template struct IsPointer : FalseType {}; 94 | template struct IsPointer : TrueType {}; 95 | 96 | /////////////////////////////////////////////////////////////////////////////// 97 | // IsBaseOf 98 | // 99 | #if RAPIDJSON_HAS_CXX11_TYPETRAITS 100 | 101 | template struct IsBaseOf 102 | : BoolType< ::std::is_base_of::value> {}; 103 | 104 | #else // simplified version adopted from Boost 105 | 106 | template struct IsBaseOfImpl { 107 | RAPIDJSON_STATIC_ASSERT(sizeof(B) != 0); 108 | RAPIDJSON_STATIC_ASSERT(sizeof(D) != 0); 109 | 110 | typedef char (&Yes)[1]; 111 | typedef char (&No) [2]; 112 | 113 | template 114 | static Yes Check(const D*, T); 115 | static No Check(const B*, int); 116 | 117 | struct Host { 118 | operator const B*() const; 119 | operator const D*(); 120 | }; 121 | 122 | enum { Value = (sizeof(Check(Host(), 0)) == sizeof(Yes)) }; 123 | }; 124 | 125 | template struct IsBaseOf 126 | : OrExpr, BoolExpr > >::Type {}; 127 | 128 | #endif // RAPIDJSON_HAS_CXX11_TYPETRAITS 129 | 130 | 131 | ////////////////////////////////////////////////////////////////////////// 132 | // EnableIf / DisableIf 133 | // 134 | template struct EnableIfCond { typedef T Type; }; 135 | template struct EnableIfCond { /* empty */ }; 136 | 137 | template struct DisableIfCond { typedef T Type; }; 138 | template struct DisableIfCond { /* empty */ }; 139 | 140 | template 141 | struct EnableIf : EnableIfCond {}; 142 | 143 | template 144 | struct DisableIf : DisableIfCond {}; 145 | 146 | // SFINAE helpers 147 | struct SfinaeTag {}; 148 | template struct RemoveSfinaeTag; 149 | template struct RemoveSfinaeTag { typedef T Type; }; 150 | 151 | #define RAPIDJSON_REMOVEFPTR_(type) \ 152 | typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \ 153 | < ::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type 154 | 155 | #define RAPIDJSON_ENABLEIF(cond) \ 156 | typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ 157 | ::Type * = NULL 158 | 159 | #define RAPIDJSON_DISABLEIF(cond) \ 160 | typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ 161 | ::Type * = NULL 162 | 163 | #define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \ 164 | typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ 165 | ::Type 167 | 168 | #define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \ 169 | typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ 170 | ::Type 172 | 173 | } // namespace internal 174 | RAPIDJSON_NAMESPACE_END 175 | //@endcond 176 | 177 | #if defined(__GNUC__) || defined(_MSC_VER) 178 | RAPIDJSON_DIAG_POP 179 | #endif 180 | 181 | #endif // RAPIDJSON_INTERNAL_META_H_ 182 | -------------------------------------------------------------------------------- /lib/rapidjson/stream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "rapidjson.h" 16 | 17 | #ifndef RAPIDJSON_STREAM_H_ 18 | #define RAPIDJSON_STREAM_H_ 19 | 20 | #include "encodings.h" 21 | 22 | RAPIDJSON_NAMESPACE_BEGIN 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | // Stream 26 | 27 | /*! \class rapidjson::Stream 28 | \brief Concept for reading and writing characters. 29 | 30 | For read-only stream, no need to implement PutBegin(), Put(), Flush() and PutEnd(). 31 | 32 | For write-only stream, only need to implement Put() and Flush(). 33 | 34 | \code 35 | concept Stream { 36 | typename Ch; //!< Character type of the stream. 37 | 38 | //! Read the current character from stream without moving the read cursor. 39 | Ch Peek() const; 40 | 41 | //! Read the current character from stream and moving the read cursor to next character. 42 | Ch Take(); 43 | 44 | //! Get the current read cursor. 45 | //! \return Number of characters read from start. 46 | size_t Tell(); 47 | 48 | //! Begin writing operation at the current read pointer. 49 | //! \return The begin writer pointer. 50 | Ch* PutBegin(); 51 | 52 | //! Write a character. 53 | void Put(Ch c); 54 | 55 | //! Flush the buffer. 56 | void Flush(); 57 | 58 | //! End the writing operation. 59 | //! \param begin The begin write pointer returned by PutBegin(). 60 | //! \return Number of characters written. 61 | size_t PutEnd(Ch* begin); 62 | } 63 | \endcode 64 | */ 65 | 66 | //! Provides additional information for stream. 67 | /*! 68 | By using traits pattern, this type provides a default configuration for stream. 69 | For custom stream, this type can be specialized for other configuration. 70 | See TEST(Reader, CustomStringStream) in readertest.cpp for example. 71 | */ 72 | template 73 | struct StreamTraits { 74 | //! Whether to make local copy of stream for optimization during parsing. 75 | /*! 76 | By default, for safety, streams do not use local copy optimization. 77 | Stream that can be copied fast should specialize this, like StreamTraits. 78 | */ 79 | enum { copyOptimization = 0 }; 80 | }; 81 | 82 | //! Reserve n characters for writing to a stream. 83 | template 84 | inline void PutReserve(Stream& stream, size_t count) { 85 | (void)stream; 86 | (void)count; 87 | } 88 | 89 | //! Write character to a stream, presuming buffer is reserved. 90 | template 91 | inline void PutUnsafe(Stream& stream, typename Stream::Ch c) { 92 | stream.Put(c); 93 | } 94 | 95 | //! Put N copies of a character to a stream. 96 | template 97 | inline void PutN(Stream& stream, Ch c, size_t n) { 98 | PutReserve(stream, n); 99 | for (size_t i = 0; i < n; i++) 100 | PutUnsafe(stream, c); 101 | } 102 | 103 | /////////////////////////////////////////////////////////////////////////////// 104 | // GenericStreamWrapper 105 | 106 | //! A Stream Wrapper 107 | /*! \tThis string stream is a wrapper for any stream by just forwarding any 108 | \treceived message to the origin stream. 109 | \note implements Stream concept 110 | */ 111 | 112 | #if defined(_MSC_VER) && _MSC_VER <= 1800 113 | RAPIDJSON_DIAG_PUSH 114 | RAPIDJSON_DIAG_OFF(4702) // unreachable code 115 | RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated 116 | #endif 117 | 118 | template > 119 | class GenericStreamWrapper { 120 | public: 121 | typedef typename Encoding::Ch Ch; 122 | GenericStreamWrapper(InputStream& is): is_(is) {} 123 | 124 | Ch Peek() const { return is_.Peek(); } 125 | Ch Take() { return is_.Take(); } 126 | size_t Tell() { return is_.Tell(); } 127 | Ch* PutBegin() { return is_.PutBegin(); } 128 | void Put(Ch ch) { is_.Put(ch); } 129 | void Flush() { is_.Flush(); } 130 | size_t PutEnd(Ch* ch) { return is_.PutEnd(ch); } 131 | 132 | // wrapper for MemoryStream 133 | const Ch* Peek4() const { return is_.Peek4(); } 134 | 135 | // wrapper for AutoUTFInputStream 136 | UTFType GetType() const { return is_.GetType(); } 137 | bool HasBOM() const { return is_.HasBOM(); } 138 | 139 | protected: 140 | InputStream& is_; 141 | }; 142 | 143 | #if defined(_MSC_VER) && _MSC_VER <= 1800 144 | RAPIDJSON_DIAG_POP 145 | #endif 146 | 147 | /////////////////////////////////////////////////////////////////////////////// 148 | // StringStream 149 | 150 | //! Read-only string stream. 151 | /*! \note implements Stream concept 152 | */ 153 | template 154 | struct GenericStringStream { 155 | typedef typename Encoding::Ch Ch; 156 | 157 | GenericStringStream(const Ch *src) : src_(src), head_(src) {} 158 | 159 | Ch Peek() const { return *src_; } 160 | Ch Take() { return *src_++; } 161 | size_t Tell() const { return static_cast(src_ - head_); } 162 | 163 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 164 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 165 | void Flush() { RAPIDJSON_ASSERT(false); } 166 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 167 | 168 | const Ch* src_; //!< Current read position. 169 | const Ch* head_; //!< Original head of the string. 170 | }; 171 | 172 | template 173 | struct StreamTraits > { 174 | enum { copyOptimization = 1 }; 175 | }; 176 | 177 | //! String stream with UTF8 encoding. 178 | typedef GenericStringStream > StringStream; 179 | 180 | /////////////////////////////////////////////////////////////////////////////// 181 | // InsituStringStream 182 | 183 | //! A read-write string stream. 184 | /*! This string stream is particularly designed for in-situ parsing. 185 | \note implements Stream concept 186 | */ 187 | template 188 | struct GenericInsituStringStream { 189 | typedef typename Encoding::Ch Ch; 190 | 191 | GenericInsituStringStream(Ch *src) : src_(src), dst_(0), head_(src) {} 192 | 193 | // Read 194 | Ch Peek() { return *src_; } 195 | Ch Take() { return *src_++; } 196 | size_t Tell() { return static_cast(src_ - head_); } 197 | 198 | // Write 199 | void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; } 200 | 201 | Ch* PutBegin() { return dst_ = src_; } 202 | size_t PutEnd(Ch* begin) { return static_cast(dst_ - begin); } 203 | void Flush() {} 204 | 205 | Ch* Push(size_t count) { Ch* begin = dst_; dst_ += count; return begin; } 206 | void Pop(size_t count) { dst_ -= count; } 207 | 208 | Ch* src_; 209 | Ch* dst_; 210 | Ch* head_; 211 | }; 212 | 213 | template 214 | struct StreamTraits > { 215 | enum { copyOptimization = 1 }; 216 | }; 217 | 218 | //! Insitu string stream with UTF8 encoding. 219 | typedef GenericInsituStringStream > InsituStringStream; 220 | 221 | RAPIDJSON_NAMESPACE_END 222 | 223 | #endif // RAPIDJSON_STREAM_H_ 224 | -------------------------------------------------------------------------------- /lib/rapidjson/internal/stack.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_STACK_H_ 16 | #define RAPIDJSON_INTERNAL_STACK_H_ 17 | 18 | #include "../allocators.h" 19 | #include "swap.h" 20 | 21 | #if defined(__clang__) 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(c++98-compat) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | namespace internal { 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // Stack 31 | 32 | //! A type-unsafe stack for storing different types of data. 33 | /*! \tparam Allocator Allocator for allocating stack memory. 34 | */ 35 | template 36 | class Stack { 37 | public: 38 | // Optimization note: Do not allocate memory for stack_ in constructor. 39 | // Do it lazily when first Push() -> Expand() -> Resize(). 40 | Stack(Allocator* allocator, size_t stackCapacity) : allocator_(allocator), ownAllocator_(0), stack_(0), stackTop_(0), stackEnd_(0), initialCapacity_(stackCapacity) { 41 | } 42 | 43 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 44 | Stack(Stack&& rhs) 45 | : allocator_(rhs.allocator_), 46 | ownAllocator_(rhs.ownAllocator_), 47 | stack_(rhs.stack_), 48 | stackTop_(rhs.stackTop_), 49 | stackEnd_(rhs.stackEnd_), 50 | initialCapacity_(rhs.initialCapacity_) 51 | { 52 | rhs.allocator_ = 0; 53 | rhs.ownAllocator_ = 0; 54 | rhs.stack_ = 0; 55 | rhs.stackTop_ = 0; 56 | rhs.stackEnd_ = 0; 57 | rhs.initialCapacity_ = 0; 58 | } 59 | #endif 60 | 61 | ~Stack() { 62 | Destroy(); 63 | } 64 | 65 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 66 | Stack& operator=(Stack&& rhs) { 67 | if (&rhs != this) 68 | { 69 | Destroy(); 70 | 71 | allocator_ = rhs.allocator_; 72 | ownAllocator_ = rhs.ownAllocator_; 73 | stack_ = rhs.stack_; 74 | stackTop_ = rhs.stackTop_; 75 | stackEnd_ = rhs.stackEnd_; 76 | initialCapacity_ = rhs.initialCapacity_; 77 | 78 | rhs.allocator_ = 0; 79 | rhs.ownAllocator_ = 0; 80 | rhs.stack_ = 0; 81 | rhs.stackTop_ = 0; 82 | rhs.stackEnd_ = 0; 83 | rhs.initialCapacity_ = 0; 84 | } 85 | return *this; 86 | } 87 | #endif 88 | 89 | void Swap(Stack& rhs) RAPIDJSON_NOEXCEPT { 90 | internal::Swap(allocator_, rhs.allocator_); 91 | internal::Swap(ownAllocator_, rhs.ownAllocator_); 92 | internal::Swap(stack_, rhs.stack_); 93 | internal::Swap(stackTop_, rhs.stackTop_); 94 | internal::Swap(stackEnd_, rhs.stackEnd_); 95 | internal::Swap(initialCapacity_, rhs.initialCapacity_); 96 | } 97 | 98 | void Clear() { stackTop_ = stack_; } 99 | 100 | void ShrinkToFit() { 101 | if (Empty()) { 102 | // If the stack is empty, completely deallocate the memory. 103 | Allocator::Free(stack_); 104 | stack_ = 0; 105 | stackTop_ = 0; 106 | stackEnd_ = 0; 107 | } 108 | else 109 | Resize(GetSize()); 110 | } 111 | 112 | // Optimization note: try to minimize the size of this function for force inline. 113 | // Expansion is run very infrequently, so it is moved to another (probably non-inline) function. 114 | template 115 | RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) { 116 | // Expand the stack if needed 117 | if (RAPIDJSON_UNLIKELY(stackTop_ + sizeof(T) * count > stackEnd_)) 118 | Expand(count); 119 | } 120 | 121 | template 122 | RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) { 123 | Reserve(count); 124 | return PushUnsafe(count); 125 | } 126 | 127 | template 128 | RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) { 129 | RAPIDJSON_ASSERT(stackTop_); 130 | RAPIDJSON_ASSERT(stackTop_ + sizeof(T) * count <= stackEnd_); 131 | T* ret = reinterpret_cast(stackTop_); 132 | stackTop_ += sizeof(T) * count; 133 | return ret; 134 | } 135 | 136 | template 137 | T* Pop(size_t count) { 138 | RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T)); 139 | stackTop_ -= count * sizeof(T); 140 | return reinterpret_cast(stackTop_); 141 | } 142 | 143 | template 144 | T* Top() { 145 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); 146 | return reinterpret_cast(stackTop_ - sizeof(T)); 147 | } 148 | 149 | template 150 | const T* Top() const { 151 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); 152 | return reinterpret_cast(stackTop_ - sizeof(T)); 153 | } 154 | 155 | template 156 | T* End() { return reinterpret_cast(stackTop_); } 157 | 158 | template 159 | const T* End() const { return reinterpret_cast(stackTop_); } 160 | 161 | template 162 | T* Bottom() { return reinterpret_cast(stack_); } 163 | 164 | template 165 | const T* Bottom() const { return reinterpret_cast(stack_); } 166 | 167 | bool HasAllocator() const { 168 | return allocator_ != 0; 169 | } 170 | 171 | Allocator& GetAllocator() { 172 | RAPIDJSON_ASSERT(allocator_); 173 | return *allocator_; 174 | } 175 | 176 | bool Empty() const { return stackTop_ == stack_; } 177 | size_t GetSize() const { return static_cast(stackTop_ - stack_); } 178 | size_t GetCapacity() const { return static_cast(stackEnd_ - stack_); } 179 | 180 | private: 181 | template 182 | void Expand(size_t count) { 183 | // Only expand the capacity if the current stack exists. Otherwise just create a stack with initial capacity. 184 | size_t newCapacity; 185 | if (stack_ == 0) { 186 | if (!allocator_) 187 | ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); 188 | newCapacity = initialCapacity_; 189 | } else { 190 | newCapacity = GetCapacity(); 191 | newCapacity += (newCapacity + 1) / 2; 192 | } 193 | size_t newSize = GetSize() + sizeof(T) * count; 194 | if (newCapacity < newSize) 195 | newCapacity = newSize; 196 | 197 | Resize(newCapacity); 198 | } 199 | 200 | void Resize(size_t newCapacity) { 201 | const size_t size = GetSize(); // Backup the current size 202 | stack_ = static_cast(allocator_->Realloc(stack_, GetCapacity(), newCapacity)); 203 | stackTop_ = stack_ + size; 204 | stackEnd_ = stack_ + newCapacity; 205 | } 206 | 207 | void Destroy() { 208 | Allocator::Free(stack_); 209 | RAPIDJSON_DELETE(ownAllocator_); // Only delete if it is owned by the stack 210 | } 211 | 212 | // Prohibit copy constructor & assignment operator. 213 | Stack(const Stack&); 214 | Stack& operator=(const Stack&); 215 | 216 | Allocator* allocator_; 217 | Allocator* ownAllocator_; 218 | char *stack_; 219 | char *stackTop_; 220 | char *stackEnd_; 221 | size_t initialCapacity_; 222 | }; 223 | 224 | } // namespace internal 225 | RAPIDJSON_NAMESPACE_END 226 | 227 | #if defined(__clang__) 228 | RAPIDJSON_DIAG_POP 229 | #endif 230 | 231 | #endif // RAPIDJSON_STACK_H_ 232 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ETS2&ATS Sync Helper 2 | 3 | ![Github All Releases](https://img.shields.io/github/downloads/Inklay/ETS2-ATS-Sync-Helper/total.svg) 4 | ![ETS2 Version](https://img.shields.io/badge/ETS2%20Version-1.39%20%2B-green) 5 | ![ETS2 DLC](https://img.shields.io/badge/ETS%20DLC-ALL-yellowgreen) 6 | ![ATS Version](https://img.shields.io/badge/ATS%20Version-1.39%20%2B-green) 7 | ![ATS DLC](https://img.shields.io/badge/ATS%20DLC-ALL-yellowgreen) 8 | 9 | * [Version française](README-fr.md) 10 | 11 | [LICENSE](LICENSE.md) 12 | 13 | * [Download](#download) 14 | * [Setting Up](#setting-up) 15 | * [How To Sync](#how-to-sync) 16 | * [Features](#features) 17 | * [Clear Jobs](#clear-jobs) 18 | * [Economy Reset](#economy-reset) 19 | * [Job List](#job-list) 20 | * [Common Errors](#common-errors) 21 | * [Bugs/Issues](#Bugs/Issues) 22 | * [Compiling The Source Code](#compiling-the-source-code) 23 | * [Dependencies](#Dependencies) 24 | * [Compilation](#Compilation) 25 | * [Backend](#Backend) 26 | 27 | This is the repository for ETS2&ATS Sync helper. The program has been rewritten from scratch in C++ by David Santos, I am now keeping up to date to support game's update and New DLCs 28 | 29 | This app synchronizes the job list on Euro Truck Simulator 2 or American Truck Simulator, in order to make it easier to organize a convoy on Multiplayer. 30 | 31 | As of now, the app is available only in English. Other languages might be added in the future. 32 | 33 | ## Download 34 | https://github.com/Inklay/ETS2-ATS-Sync-Helper/releases 35 | 36 | ## Setting Up 37 | Open ETS2Sync Helper and select the game (ETS2 or ATS). Look in the “Game Settings” panel. If there is a message in green saying “Settings OK”, you're all set. If the message is yellow or red, you need to do this: 38 | 1. Make sure the game is closed. This won't work if you do it with the game running. 39 | 2. In ETS2Sync Helper, in the “Game Settings” panel, in the “Save Format” line, click “Set to ‘Text’”. The yellow or red message should turn green and say “Settings OK”. That's it. Now your game is set up for syncing, so you can go to [How To Sync](#how-to-sync). 40 | 41 | 42 | ## How To Sync 43 | 1. Go to the main screen (if you are driving, hit Esc). 44 | 2. Click on “Save & Load” → “Save Game”. 45 | 3. Type a name for the save or select an existing save to overwrite it. 46 | 4. Click “Save”. 47 | 5. Hit `Alt`+`Tab` to minimize the game. 48 | 6. Open ETS2Sync Helper if it isn't already open. Make sure the correct game is selected in the “Game” option of the “Game Settings” panel. 49 | 7. Make sure the correct profile and save are selected in the “Select ETS2/ATS Profile” and “Select ETS2/ATS Save” panels. 50 | 8. Select the DLCs you and your friends have (do not select a DLC unless everyone you're playing with owns it too). 51 | 9. Click “Sync Jobs”. 52 | 10. When the message “Sync Complete” appears, click “Close”. 53 | 11. Go back to the game. 54 | 12. Click on “Save & Load” → “Load Game”. 55 | 13. Select the save you just synced (the one you created/replaced in step 4). 56 | 14. Click “Load”. 57 | 15. Check the Freight Market and or the Cargo Market. If all jobs have the same time to expire (“Offer expires in”), and it's about 400 to 500 hours, then the sync was successful. 58 | 59 | ## Features 60 | ### Clear Jobs 61 | This feature gives you the ability to empty the Freight Market. That way, if you are done using the synced list and want the game to generate a new list of jobs for you to play alone, you just need to do the same process as for syncing, but click on “Clear Jobs” instead of “Sync Jobs”. When you load the save, the Freight Market will be empty. Just jump to the mechanic with F7 or do a Quick Trip or two and the game will generate new jobs for you. 62 | 63 | ### Economy Reset 64 | This feature works like Clear Jobs, but it's faster because when you load the save the game will show a “Game Change Detected” message, which will instantly generate new jobs (i.e. no need to call Assistance or do Quick Travels to populate the Freight Market). A downside is that it will also move you to your home garage. 65 | 66 | ### Job List 67 | When you sync, the app downloads a list of jobs from the server and inserts it into your save. There are eight job lists for ETS2 and eight for ATS on the server. One of those eight lists is the one that is used when you leave the “Job List” option in the “Automatic” setting. Every Wednesday the active list switches to the next one (i.e. if List 7 is the active list, then on Wednesday it will switch to List 8, and on the following Wednesday it goes back to List 1). 68 | 69 | The job lists themselves don't change, except for when a game update makes it necessary (a game or DLC update or a new DLC). So, if you want the list of jobs not to change—for example, if it's Monday and you are planning a convoy for the weekend—, just manually select one of the eight lists and be sure to tell everyone in the convoy to pick the same job list in the app before syncing. 70 | 71 | ## Common Errors 72 | 73 | ### Unfortunately, binary saves aren't supported. Please create the save using a text format. 74 | You selected an old save or the game isn't set up properly. 75 | * If ETS2Sync Helper doesn't show a green “Settings OK” message in the “Game Settings” panel, you need to do the steps in the [Setting Up](#setting-up) section again. 76 | * If it was already showing “Settings OK”, make sure the correct profile and save are selected before syncing. 77 | * If it still doesn't work, close ETS2Sync Helper and close the game, then reopen ETS2Sync Helper and see if the green “Settings OK” message is there. If it isn't, see above. If it is, open the game and make sure to create a new save before syncing again. 78 | 79 | ### Could not download the job list. InternetOpenURL error 80 | ### Could not download the job list. HTTP 500 Internal Server Error 81 | ### Could not download the job list. HTTP 401 Unauthorized 82 | ### Could not download the job list. HTTP 403 Forbidden 83 | ### Could not download the job list. HTTP 404 Not Found 84 | This is likely a temporary issue with your Internet connection or with the server from which ETS2&ATS Sync Helper downloads the job list. If your Internet connection is working properly, wait a few minutes and try again. 85 | 86 | ## Bugs/Issues 87 | If you find a problem in the app, report it on the link below: 88 | 89 | https://github.com/Inklay/ETS2-ATS-Sync-Helper/issues 90 | 91 | ## Compiling The Source Code 92 | Before you can compile, you need to set up the dependencies. 93 | 94 | ### Dependencies 95 | For those that need to be compiled, compilation instructions can often be found in the downloaded package or in the library's documentation. 96 | 97 | * **wxWidgets 3.1** — download and compile, then set the environment variable `WXWIN` to its directory. 98 | 99 | wxWidgets provides several utility classes used in the app, most importantly the GUI and thread support. The app code would be a lot more complex if those had to be implemented using the native Windows API. 100 | * **zlib** — download and compile, then set the environment variable `ZLIBDIR` to its directory. 101 | 102 | When encrypted `.sii` files are generated by the games, the data is compressed and then encrypted. Zlib is used to decompress the data, after it is decrypted. 103 | * **Ragel 6** — download and install a binary version for Windows (`ragel.exe`) or download and compile the source code, then add the directory of `ragel.exe` to your `PATH`. 104 | 105 | Ragel is used to generate the code for the state machines that parse `.cfg` and text-mode `.sii` files. 106 | * **GraphViz** — download and install a binary version for Windows or download and compile, then add the directory of `dot.exe` to your `PATH`. 107 | 108 | GraphViz generates a visual representation of the parsers generated by Ragel. That makes it easier to understand how those parsers work and therefore how to fix problems in them if they arise. 109 | 110 | ### Compilation 111 | Once the dependencies are in place, just open `ETS2Sync-Helper-4.sln` in Visual Studio 2017 and compile normally. Be aware that in a debug build the sync process is noticeably slower. 112 | 113 | ### Backend 114 | The backend code can be found here: https://github.com/Inklay/Inklay.net 115 | -------------------------------------------------------------------------------- /ETS2Sync-Helper-4.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | Source Files 68 | 69 | 70 | Source Files 71 | 72 | 73 | Source Files 74 | 75 | 76 | Source Files 77 | 78 | 79 | Source Files 80 | 81 | 82 | Source Files 83 | 84 | 85 | Source Files 86 | 87 | 88 | Source Files 89 | 90 | 91 | Source Files 92 | 93 | 94 | 95 | 96 | Header Files 97 | 98 | 99 | Header Files 100 | 101 | 102 | Header Files 103 | 104 | 105 | Header Files 106 | 107 | 108 | Header Files 109 | 110 | 111 | Header Files 112 | 113 | 114 | Header Files 115 | 116 | 117 | Header Files 118 | 119 | 120 | Header Files 121 | 122 | 123 | Header Files 124 | 125 | 126 | Header Files 127 | 128 | 129 | Header Files 130 | 131 | 132 | Header Files 133 | 134 | 135 | Header Files 136 | 137 | 138 | Header Files 139 | 140 | 141 | Header Files 142 | 143 | 144 | Header Files 145 | 146 | 147 | Header Files 148 | 149 | 150 | Header Files 151 | 152 | 153 | Header Files 154 | 155 | 156 | Header Files 157 | 158 | 159 | Header Files 160 | 161 | 162 | Header Files 163 | 164 | 165 | Header Files 166 | 167 | 168 | Header Files 169 | 170 | 171 | Header Files 172 | 173 | 174 | Header Files 175 | 176 | 177 | Header Files 178 | 179 | 180 | Header Files 181 | 182 | 183 | Header Files 184 | 185 | 186 | Header Files 187 | 188 | 189 | Header Files 190 | 191 | 192 | Header Files 193 | 194 | 195 | Header Files 196 | 197 | 198 | 199 | 200 | Resource Files 201 | 202 | 203 | Resource Files 204 | 205 | 206 | 207 | 208 | Resource Files 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | Source Files 219 | 220 | 221 | -------------------------------------------------------------------------------- /lib/rapidjson/internal/dtoa.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | // This is a C++ header-only implementation of Grisu2 algorithm from the publication: 16 | // Loitsch, Florian. "Printing floating-point numbers quickly and accurately with 17 | // integers." ACM Sigplan Notices 45.6 (2010): 233-243. 18 | 19 | #ifndef RAPIDJSON_DTOA_ 20 | #define RAPIDJSON_DTOA_ 21 | 22 | #include "itoa.h" // GetDigitsLut() 23 | #include "diyfp.h" 24 | #include "ieee754.h" 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | namespace internal { 28 | 29 | #ifdef __GNUC__ 30 | RAPIDJSON_DIAG_PUSH 31 | RAPIDJSON_DIAG_OFF(effc++) 32 | RAPIDJSON_DIAG_OFF(array-bounds) // some gcc versions generate wrong warnings https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124 33 | #endif 34 | 35 | inline void GrisuRound(char* buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) { 36 | while (rest < wp_w && delta - rest >= ten_kappa && 37 | (rest + ten_kappa < wp_w || /// closer 38 | wp_w - rest > rest + ten_kappa - wp_w)) { 39 | buffer[len - 1]--; 40 | rest += ten_kappa; 41 | } 42 | } 43 | 44 | inline int CountDecimalDigit32(uint32_t n) { 45 | // Simple pure C++ implementation was faster than __builtin_clz version in this situation. 46 | if (n < 10) return 1; 47 | if (n < 100) return 2; 48 | if (n < 1000) return 3; 49 | if (n < 10000) return 4; 50 | if (n < 100000) return 5; 51 | if (n < 1000000) return 6; 52 | if (n < 10000000) return 7; 53 | if (n < 100000000) return 8; 54 | // Will not reach 10 digits in DigitGen() 55 | //if (n < 1000000000) return 9; 56 | //return 10; 57 | return 9; 58 | } 59 | 60 | inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) { 61 | static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; 62 | const DiyFp one(uint64_t(1) << -Mp.e, Mp.e); 63 | const DiyFp wp_w = Mp - W; 64 | uint32_t p1 = static_cast(Mp.f >> -one.e); 65 | uint64_t p2 = Mp.f & (one.f - 1); 66 | int kappa = CountDecimalDigit32(p1); // kappa in [0, 9] 67 | *len = 0; 68 | 69 | while (kappa > 0) { 70 | uint32_t d = 0; 71 | switch (kappa) { 72 | case 9: d = p1 / 100000000; p1 %= 100000000; break; 73 | case 8: d = p1 / 10000000; p1 %= 10000000; break; 74 | case 7: d = p1 / 1000000; p1 %= 1000000; break; 75 | case 6: d = p1 / 100000; p1 %= 100000; break; 76 | case 5: d = p1 / 10000; p1 %= 10000; break; 77 | case 4: d = p1 / 1000; p1 %= 1000; break; 78 | case 3: d = p1 / 100; p1 %= 100; break; 79 | case 2: d = p1 / 10; p1 %= 10; break; 80 | case 1: d = p1; p1 = 0; break; 81 | default:; 82 | } 83 | if (d || *len) 84 | buffer[(*len)++] = static_cast('0' + static_cast(d)); 85 | kappa--; 86 | uint64_t tmp = (static_cast(p1) << -one.e) + p2; 87 | if (tmp <= delta) { 88 | *K += kappa; 89 | GrisuRound(buffer, *len, delta, tmp, static_cast(kPow10[kappa]) << -one.e, wp_w.f); 90 | return; 91 | } 92 | } 93 | 94 | // kappa = 0 95 | for (;;) { 96 | p2 *= 10; 97 | delta *= 10; 98 | char d = static_cast(p2 >> -one.e); 99 | if (d || *len) 100 | buffer[(*len)++] = static_cast('0' + d); 101 | p2 &= one.f - 1; 102 | kappa--; 103 | if (p2 < delta) { 104 | *K += kappa; 105 | int index = -kappa; 106 | GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 9 ? kPow10[index] : 0)); 107 | return; 108 | } 109 | } 110 | } 111 | 112 | inline void Grisu2(double value, char* buffer, int* length, int* K) { 113 | const DiyFp v(value); 114 | DiyFp w_m, w_p; 115 | v.NormalizedBoundaries(&w_m, &w_p); 116 | 117 | const DiyFp c_mk = GetCachedPower(w_p.e, K); 118 | const DiyFp W = v.Normalize() * c_mk; 119 | DiyFp Wp = w_p * c_mk; 120 | DiyFp Wm = w_m * c_mk; 121 | Wm.f++; 122 | Wp.f--; 123 | DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K); 124 | } 125 | 126 | inline char* WriteExponent(int K, char* buffer) { 127 | if (K < 0) { 128 | *buffer++ = '-'; 129 | K = -K; 130 | } 131 | 132 | if (K >= 100) { 133 | *buffer++ = static_cast('0' + static_cast(K / 100)); 134 | K %= 100; 135 | const char* d = GetDigitsLut() + K * 2; 136 | *buffer++ = d[0]; 137 | *buffer++ = d[1]; 138 | } 139 | else if (K >= 10) { 140 | const char* d = GetDigitsLut() + K * 2; 141 | *buffer++ = d[0]; 142 | *buffer++ = d[1]; 143 | } 144 | else 145 | *buffer++ = static_cast('0' + static_cast(K)); 146 | 147 | return buffer; 148 | } 149 | 150 | inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) { 151 | const int kk = length + k; // 10^(kk-1) <= v < 10^kk 152 | 153 | if (0 <= k && kk <= 21) { 154 | // 1234e7 -> 12340000000 155 | for (int i = length; i < kk; i++) 156 | buffer[i] = '0'; 157 | buffer[kk] = '.'; 158 | buffer[kk + 1] = '0'; 159 | return &buffer[kk + 2]; 160 | } 161 | else if (0 < kk && kk <= 21) { 162 | // 1234e-2 -> 12.34 163 | std::memmove(&buffer[kk + 1], &buffer[kk], static_cast(length - kk)); 164 | buffer[kk] = '.'; 165 | if (0 > k + maxDecimalPlaces) { 166 | // When maxDecimalPlaces = 2, 1.2345 -> 1.23, 1.102 -> 1.1 167 | // Remove extra trailing zeros (at least one) after truncation. 168 | for (int i = kk + maxDecimalPlaces; i > kk + 1; i--) 169 | if (buffer[i] != '0') 170 | return &buffer[i + 1]; 171 | return &buffer[kk + 2]; // Reserve one zero 172 | } 173 | else 174 | return &buffer[length + 1]; 175 | } 176 | else if (-6 < kk && kk <= 0) { 177 | // 1234e-6 -> 0.001234 178 | const int offset = 2 - kk; 179 | std::memmove(&buffer[offset], &buffer[0], static_cast(length)); 180 | buffer[0] = '0'; 181 | buffer[1] = '.'; 182 | for (int i = 2; i < offset; i++) 183 | buffer[i] = '0'; 184 | if (length - kk > maxDecimalPlaces) { 185 | // When maxDecimalPlaces = 2, 0.123 -> 0.12, 0.102 -> 0.1 186 | // Remove extra trailing zeros (at least one) after truncation. 187 | for (int i = maxDecimalPlaces + 1; i > 2; i--) 188 | if (buffer[i] != '0') 189 | return &buffer[i + 1]; 190 | return &buffer[3]; // Reserve one zero 191 | } 192 | else 193 | return &buffer[length + offset]; 194 | } 195 | else if (kk < -maxDecimalPlaces) { 196 | // Truncate to zero 197 | buffer[0] = '0'; 198 | buffer[1] = '.'; 199 | buffer[2] = '0'; 200 | return &buffer[3]; 201 | } 202 | else if (length == 1) { 203 | // 1e30 204 | buffer[1] = 'e'; 205 | return WriteExponent(kk - 1, &buffer[2]); 206 | } 207 | else { 208 | // 1234e30 -> 1.234e33 209 | std::memmove(&buffer[2], &buffer[1], static_cast(length - 1)); 210 | buffer[1] = '.'; 211 | buffer[length + 1] = 'e'; 212 | return WriteExponent(kk - 1, &buffer[0 + length + 2]); 213 | } 214 | } 215 | 216 | inline char* dtoa(double value, char* buffer, int maxDecimalPlaces = 324) { 217 | RAPIDJSON_ASSERT(maxDecimalPlaces >= 1); 218 | Double d(value); 219 | if (d.IsZero()) { 220 | if (d.Sign()) 221 | *buffer++ = '-'; // -0.0, Issue #289 222 | buffer[0] = '0'; 223 | buffer[1] = '.'; 224 | buffer[2] = '0'; 225 | return &buffer[3]; 226 | } 227 | else { 228 | if (value < 0) { 229 | *buffer++ = '-'; 230 | value = -value; 231 | } 232 | int length, K; 233 | Grisu2(value, buffer, &length, &K); 234 | return Prettify(buffer, length, K, maxDecimalPlaces); 235 | } 236 | } 237 | 238 | #ifdef __GNUC__ 239 | RAPIDJSON_DIAG_POP 240 | #endif 241 | 242 | } // namespace internal 243 | RAPIDJSON_NAMESPACE_END 244 | 245 | #endif // RAPIDJSON_DTOA_ 246 | -------------------------------------------------------------------------------- /lib/rapidjson/internal/strtod.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_STRTOD_ 16 | #define RAPIDJSON_STRTOD_ 17 | 18 | #include "ieee754.h" 19 | #include "biginteger.h" 20 | #include "diyfp.h" 21 | #include "pow10.h" 22 | 23 | RAPIDJSON_NAMESPACE_BEGIN 24 | namespace internal { 25 | 26 | inline double FastPath(double significand, int exp) { 27 | if (exp < -308) 28 | return 0.0; 29 | else if (exp >= 0) 30 | return significand * internal::Pow10(exp); 31 | else 32 | return significand / internal::Pow10(-exp); 33 | } 34 | 35 | inline double StrtodNormalPrecision(double d, int p) { 36 | if (p < -308) { 37 | // Prevent expSum < -308, making Pow10(p) = 0 38 | d = FastPath(d, -308); 39 | d = FastPath(d, p + 308); 40 | } 41 | else 42 | d = FastPath(d, p); 43 | return d; 44 | } 45 | 46 | template 47 | inline T Min3(T a, T b, T c) { 48 | T m = a; 49 | if (m > b) m = b; 50 | if (m > c) m = c; 51 | return m; 52 | } 53 | 54 | inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) { 55 | const Double db(b); 56 | const uint64_t bInt = db.IntegerSignificand(); 57 | const int bExp = db.IntegerExponent(); 58 | const int hExp = bExp - 1; 59 | 60 | int dS_Exp2 = 0, dS_Exp5 = 0, bS_Exp2 = 0, bS_Exp5 = 0, hS_Exp2 = 0, hS_Exp5 = 0; 61 | 62 | // Adjust for decimal exponent 63 | if (dExp >= 0) { 64 | dS_Exp2 += dExp; 65 | dS_Exp5 += dExp; 66 | } 67 | else { 68 | bS_Exp2 -= dExp; 69 | bS_Exp5 -= dExp; 70 | hS_Exp2 -= dExp; 71 | hS_Exp5 -= dExp; 72 | } 73 | 74 | // Adjust for binary exponent 75 | if (bExp >= 0) 76 | bS_Exp2 += bExp; 77 | else { 78 | dS_Exp2 -= bExp; 79 | hS_Exp2 -= bExp; 80 | } 81 | 82 | // Adjust for half ulp exponent 83 | if (hExp >= 0) 84 | hS_Exp2 += hExp; 85 | else { 86 | dS_Exp2 -= hExp; 87 | bS_Exp2 -= hExp; 88 | } 89 | 90 | // Remove common power of two factor from all three scaled values 91 | int common_Exp2 = Min3(dS_Exp2, bS_Exp2, hS_Exp2); 92 | dS_Exp2 -= common_Exp2; 93 | bS_Exp2 -= common_Exp2; 94 | hS_Exp2 -= common_Exp2; 95 | 96 | BigInteger dS = d; 97 | dS.MultiplyPow5(static_cast(dS_Exp5)) <<= static_cast(dS_Exp2); 98 | 99 | BigInteger bS(bInt); 100 | bS.MultiplyPow5(static_cast(bS_Exp5)) <<= static_cast(bS_Exp2); 101 | 102 | BigInteger hS(1); 103 | hS.MultiplyPow5(static_cast(hS_Exp5)) <<= static_cast(hS_Exp2); 104 | 105 | BigInteger delta(0); 106 | dS.Difference(bS, &delta); 107 | 108 | return delta.Compare(hS); 109 | } 110 | 111 | inline bool StrtodFast(double d, int p, double* result) { 112 | // Use fast path for string-to-double conversion if possible 113 | // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/ 114 | if (p > 22 && p < 22 + 16) { 115 | // Fast Path Cases In Disguise 116 | d *= internal::Pow10(p - 22); 117 | p = 22; 118 | } 119 | 120 | if (p >= -22 && p <= 22 && d <= 9007199254740991.0) { // 2^53 - 1 121 | *result = FastPath(d, p); 122 | return true; 123 | } 124 | else 125 | return false; 126 | } 127 | 128 | // Compute an approximation and see if it is within 1/2 ULP 129 | inline bool StrtodDiyFp(const char* decimals, size_t length, size_t decimalPosition, int exp, double* result) { 130 | uint64_t significand = 0; 131 | size_t i = 0; // 2^64 - 1 = 18446744073709551615, 1844674407370955161 = 0x1999999999999999 132 | for (; i < length; i++) { 133 | if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) || 134 | (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > '5')) 135 | break; 136 | significand = significand * 10u + static_cast(decimals[i] - '0'); 137 | } 138 | 139 | if (i < length && decimals[i] >= '5') // Rounding 140 | significand++; 141 | 142 | size_t remaining = length - i; 143 | const int kUlpShift = 3; 144 | const int kUlp = 1 << kUlpShift; 145 | int64_t error = (remaining == 0) ? 0 : kUlp / 2; 146 | 147 | DiyFp v(significand, 0); 148 | v = v.Normalize(); 149 | error <<= -v.e; 150 | 151 | const int dExp = static_cast(decimalPosition) - static_cast(i) + exp; 152 | 153 | int actualExp; 154 | DiyFp cachedPower = GetCachedPower10(dExp, &actualExp); 155 | if (actualExp != dExp) { 156 | static const DiyFp kPow10[] = { 157 | DiyFp(RAPIDJSON_UINT64_C2(0xa0000000, 00000000), -60), // 10^1 158 | DiyFp(RAPIDJSON_UINT64_C2(0xc8000000, 00000000), -57), // 10^2 159 | DiyFp(RAPIDJSON_UINT64_C2(0xfa000000, 00000000), -54), // 10^3 160 | DiyFp(RAPIDJSON_UINT64_C2(0x9c400000, 00000000), -50), // 10^4 161 | DiyFp(RAPIDJSON_UINT64_C2(0xc3500000, 00000000), -47), // 10^5 162 | DiyFp(RAPIDJSON_UINT64_C2(0xf4240000, 00000000), -44), // 10^6 163 | DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 00000000), -40) // 10^7 164 | }; 165 | int adjustment = dExp - actualExp - 1; 166 | RAPIDJSON_ASSERT(adjustment >= 0 && adjustment < 7); 167 | v = v * kPow10[adjustment]; 168 | if (length + static_cast(adjustment)> 19u) // has more digits than decimal digits in 64-bit 169 | error += kUlp / 2; 170 | } 171 | 172 | v = v * cachedPower; 173 | 174 | error += kUlp + (error == 0 ? 0 : 1); 175 | 176 | const int oldExp = v.e; 177 | v = v.Normalize(); 178 | error <<= oldExp - v.e; 179 | 180 | const int effectiveSignificandSize = Double::EffectiveSignificandSize(64 + v.e); 181 | int precisionSize = 64 - effectiveSignificandSize; 182 | if (precisionSize + kUlpShift >= 64) { 183 | int scaleExp = (precisionSize + kUlpShift) - 63; 184 | v.f >>= scaleExp; 185 | v.e += scaleExp; 186 | error = (error >> scaleExp) + 1 + kUlp; 187 | precisionSize -= scaleExp; 188 | } 189 | 190 | DiyFp rounded(v.f >> precisionSize, v.e + precisionSize); 191 | const uint64_t precisionBits = (v.f & ((uint64_t(1) << precisionSize) - 1)) * kUlp; 192 | const uint64_t halfWay = (uint64_t(1) << (precisionSize - 1)) * kUlp; 193 | if (precisionBits >= halfWay + static_cast(error)) { 194 | rounded.f++; 195 | if (rounded.f & (DiyFp::kDpHiddenBit << 1)) { // rounding overflows mantissa (issue #340) 196 | rounded.f >>= 1; 197 | rounded.e++; 198 | } 199 | } 200 | 201 | *result = rounded.ToDouble(); 202 | 203 | return halfWay - static_cast(error) >= precisionBits || precisionBits >= halfWay + static_cast(error); 204 | } 205 | 206 | inline double StrtodBigInteger(double approx, const char* decimals, size_t length, size_t decimalPosition, int exp) { 207 | const BigInteger dInt(decimals, length); 208 | const int dExp = static_cast(decimalPosition) - static_cast(length) + exp; 209 | Double a(approx); 210 | int cmp = CheckWithinHalfULP(a.Value(), dInt, dExp); 211 | if (cmp < 0) 212 | return a.Value(); // within half ULP 213 | else if (cmp == 0) { 214 | // Round towards even 215 | if (a.Significand() & 1) 216 | return a.NextPositiveDouble(); 217 | else 218 | return a.Value(); 219 | } 220 | else // adjustment 221 | return a.NextPositiveDouble(); 222 | } 223 | 224 | inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t length, size_t decimalPosition, int exp) { 225 | RAPIDJSON_ASSERT(d >= 0.0); 226 | RAPIDJSON_ASSERT(length >= 1); 227 | 228 | double result; 229 | if (StrtodFast(d, p, &result)) 230 | return result; 231 | 232 | // Trim leading zeros 233 | while (*decimals == '0' && length > 1) { 234 | length--; 235 | decimals++; 236 | decimalPosition--; 237 | } 238 | 239 | // Trim trailing zeros 240 | while (decimals[length - 1] == '0' && length > 1) { 241 | length--; 242 | decimalPosition--; 243 | exp++; 244 | } 245 | 246 | // Trim right-most digits 247 | const int kMaxDecimalDigit = 780; 248 | if (static_cast(length) > kMaxDecimalDigit) { 249 | int delta = (static_cast(length) - kMaxDecimalDigit); 250 | exp += delta; 251 | decimalPosition -= static_cast(delta); 252 | length = kMaxDecimalDigit; 253 | } 254 | 255 | // If too small, underflow to zero 256 | if (int(length) + exp < -324) 257 | return 0.0; 258 | 259 | if (StrtodDiyFp(decimals, length, decimalPosition, exp, &result)) 260 | return result; 261 | 262 | // Use approximation from StrtodDiyFp and make adjustment with BigInteger comparison 263 | return StrtodBigInteger(result, decimals, length, decimalPosition, exp); 264 | } 265 | 266 | } // namespace internal 267 | RAPIDJSON_NAMESPACE_END 268 | 269 | #endif // RAPIDJSON_STRTOD_ 270 | -------------------------------------------------------------------------------- /lib/rapidjson/msinttypes/inttypes.h: -------------------------------------------------------------------------------- 1 | // ISO C9x compliant inttypes.h for Microsoft Visual Studio 2 | // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 3 | // 4 | // Copyright (c) 2006-2013 Alexander Chemeris 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright 13 | // notice, this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // 3. Neither the name of the product nor the names of its contributors may 17 | // be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 22 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 23 | // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | // 31 | /////////////////////////////////////////////////////////////////////////////// 32 | 33 | // The above software in this distribution may have been modified by 34 | // THL A29 Limited ("Tencent Modifications"). 35 | // All Tencent Modifications are Copyright (C) 2015 THL A29 Limited. 36 | 37 | #ifndef _MSC_VER // [ 38 | #error "Use this header only with Microsoft Visual C++ compilers!" 39 | #endif // _MSC_VER ] 40 | 41 | #ifndef _MSC_INTTYPES_H_ // [ 42 | #define _MSC_INTTYPES_H_ 43 | 44 | #if _MSC_VER > 1000 45 | #pragma once 46 | #endif 47 | 48 | #include "stdint.h" 49 | 50 | // miloyip: VC supports inttypes.h since VC2013 51 | #if _MSC_VER >= 1800 52 | #include 53 | #else 54 | 55 | // 7.8 Format conversion of integer types 56 | 57 | typedef struct { 58 | intmax_t quot; 59 | intmax_t rem; 60 | } imaxdiv_t; 61 | 62 | // 7.8.1 Macros for format specifiers 63 | 64 | #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 65 | 66 | // The fprintf macros for signed integers are: 67 | #define PRId8 "d" 68 | #define PRIi8 "i" 69 | #define PRIdLEAST8 "d" 70 | #define PRIiLEAST8 "i" 71 | #define PRIdFAST8 "d" 72 | #define PRIiFAST8 "i" 73 | 74 | #define PRId16 "hd" 75 | #define PRIi16 "hi" 76 | #define PRIdLEAST16 "hd" 77 | #define PRIiLEAST16 "hi" 78 | #define PRIdFAST16 "hd" 79 | #define PRIiFAST16 "hi" 80 | 81 | #define PRId32 "I32d" 82 | #define PRIi32 "I32i" 83 | #define PRIdLEAST32 "I32d" 84 | #define PRIiLEAST32 "I32i" 85 | #define PRIdFAST32 "I32d" 86 | #define PRIiFAST32 "I32i" 87 | 88 | #define PRId64 "I64d" 89 | #define PRIi64 "I64i" 90 | #define PRIdLEAST64 "I64d" 91 | #define PRIiLEAST64 "I64i" 92 | #define PRIdFAST64 "I64d" 93 | #define PRIiFAST64 "I64i" 94 | 95 | #define PRIdMAX "I64d" 96 | #define PRIiMAX "I64i" 97 | 98 | #define PRIdPTR "Id" 99 | #define PRIiPTR "Ii" 100 | 101 | // The fprintf macros for unsigned integers are: 102 | #define PRIo8 "o" 103 | #define PRIu8 "u" 104 | #define PRIx8 "x" 105 | #define PRIX8 "X" 106 | #define PRIoLEAST8 "o" 107 | #define PRIuLEAST8 "u" 108 | #define PRIxLEAST8 "x" 109 | #define PRIXLEAST8 "X" 110 | #define PRIoFAST8 "o" 111 | #define PRIuFAST8 "u" 112 | #define PRIxFAST8 "x" 113 | #define PRIXFAST8 "X" 114 | 115 | #define PRIo16 "ho" 116 | #define PRIu16 "hu" 117 | #define PRIx16 "hx" 118 | #define PRIX16 "hX" 119 | #define PRIoLEAST16 "ho" 120 | #define PRIuLEAST16 "hu" 121 | #define PRIxLEAST16 "hx" 122 | #define PRIXLEAST16 "hX" 123 | #define PRIoFAST16 "ho" 124 | #define PRIuFAST16 "hu" 125 | #define PRIxFAST16 "hx" 126 | #define PRIXFAST16 "hX" 127 | 128 | #define PRIo32 "I32o" 129 | #define PRIu32 "I32u" 130 | #define PRIx32 "I32x" 131 | #define PRIX32 "I32X" 132 | #define PRIoLEAST32 "I32o" 133 | #define PRIuLEAST32 "I32u" 134 | #define PRIxLEAST32 "I32x" 135 | #define PRIXLEAST32 "I32X" 136 | #define PRIoFAST32 "I32o" 137 | #define PRIuFAST32 "I32u" 138 | #define PRIxFAST32 "I32x" 139 | #define PRIXFAST32 "I32X" 140 | 141 | #define PRIo64 "I64o" 142 | #define PRIu64 "I64u" 143 | #define PRIx64 "I64x" 144 | #define PRIX64 "I64X" 145 | #define PRIoLEAST64 "I64o" 146 | #define PRIuLEAST64 "I64u" 147 | #define PRIxLEAST64 "I64x" 148 | #define PRIXLEAST64 "I64X" 149 | #define PRIoFAST64 "I64o" 150 | #define PRIuFAST64 "I64u" 151 | #define PRIxFAST64 "I64x" 152 | #define PRIXFAST64 "I64X" 153 | 154 | #define PRIoMAX "I64o" 155 | #define PRIuMAX "I64u" 156 | #define PRIxMAX "I64x" 157 | #define PRIXMAX "I64X" 158 | 159 | #define PRIoPTR "Io" 160 | #define PRIuPTR "Iu" 161 | #define PRIxPTR "Ix" 162 | #define PRIXPTR "IX" 163 | 164 | // The fscanf macros for signed integers are: 165 | #define SCNd8 "d" 166 | #define SCNi8 "i" 167 | #define SCNdLEAST8 "d" 168 | #define SCNiLEAST8 "i" 169 | #define SCNdFAST8 "d" 170 | #define SCNiFAST8 "i" 171 | 172 | #define SCNd16 "hd" 173 | #define SCNi16 "hi" 174 | #define SCNdLEAST16 "hd" 175 | #define SCNiLEAST16 "hi" 176 | #define SCNdFAST16 "hd" 177 | #define SCNiFAST16 "hi" 178 | 179 | #define SCNd32 "ld" 180 | #define SCNi32 "li" 181 | #define SCNdLEAST32 "ld" 182 | #define SCNiLEAST32 "li" 183 | #define SCNdFAST32 "ld" 184 | #define SCNiFAST32 "li" 185 | 186 | #define SCNd64 "I64d" 187 | #define SCNi64 "I64i" 188 | #define SCNdLEAST64 "I64d" 189 | #define SCNiLEAST64 "I64i" 190 | #define SCNdFAST64 "I64d" 191 | #define SCNiFAST64 "I64i" 192 | 193 | #define SCNdMAX "I64d" 194 | #define SCNiMAX "I64i" 195 | 196 | #ifdef _WIN64 // [ 197 | # define SCNdPTR "I64d" 198 | # define SCNiPTR "I64i" 199 | #else // _WIN64 ][ 200 | # define SCNdPTR "ld" 201 | # define SCNiPTR "li" 202 | #endif // _WIN64 ] 203 | 204 | // The fscanf macros for unsigned integers are: 205 | #define SCNo8 "o" 206 | #define SCNu8 "u" 207 | #define SCNx8 "x" 208 | #define SCNX8 "X" 209 | #define SCNoLEAST8 "o" 210 | #define SCNuLEAST8 "u" 211 | #define SCNxLEAST8 "x" 212 | #define SCNXLEAST8 "X" 213 | #define SCNoFAST8 "o" 214 | #define SCNuFAST8 "u" 215 | #define SCNxFAST8 "x" 216 | #define SCNXFAST8 "X" 217 | 218 | #define SCNo16 "ho" 219 | #define SCNu16 "hu" 220 | #define SCNx16 "hx" 221 | #define SCNX16 "hX" 222 | #define SCNoLEAST16 "ho" 223 | #define SCNuLEAST16 "hu" 224 | #define SCNxLEAST16 "hx" 225 | #define SCNXLEAST16 "hX" 226 | #define SCNoFAST16 "ho" 227 | #define SCNuFAST16 "hu" 228 | #define SCNxFAST16 "hx" 229 | #define SCNXFAST16 "hX" 230 | 231 | #define SCNo32 "lo" 232 | #define SCNu32 "lu" 233 | #define SCNx32 "lx" 234 | #define SCNX32 "lX" 235 | #define SCNoLEAST32 "lo" 236 | #define SCNuLEAST32 "lu" 237 | #define SCNxLEAST32 "lx" 238 | #define SCNXLEAST32 "lX" 239 | #define SCNoFAST32 "lo" 240 | #define SCNuFAST32 "lu" 241 | #define SCNxFAST32 "lx" 242 | #define SCNXFAST32 "lX" 243 | 244 | #define SCNo64 "I64o" 245 | #define SCNu64 "I64u" 246 | #define SCNx64 "I64x" 247 | #define SCNX64 "I64X" 248 | #define SCNoLEAST64 "I64o" 249 | #define SCNuLEAST64 "I64u" 250 | #define SCNxLEAST64 "I64x" 251 | #define SCNXLEAST64 "I64X" 252 | #define SCNoFAST64 "I64o" 253 | #define SCNuFAST64 "I64u" 254 | #define SCNxFAST64 "I64x" 255 | #define SCNXFAST64 "I64X" 256 | 257 | #define SCNoMAX "I64o" 258 | #define SCNuMAX "I64u" 259 | #define SCNxMAX "I64x" 260 | #define SCNXMAX "I64X" 261 | 262 | #ifdef _WIN64 // [ 263 | # define SCNoPTR "I64o" 264 | # define SCNuPTR "I64u" 265 | # define SCNxPTR "I64x" 266 | # define SCNXPTR "I64X" 267 | #else // _WIN64 ][ 268 | # define SCNoPTR "lo" 269 | # define SCNuPTR "lu" 270 | # define SCNxPTR "lx" 271 | # define SCNXPTR "lX" 272 | #endif // _WIN64 ] 273 | 274 | #endif // __STDC_FORMAT_MACROS ] 275 | 276 | // 7.8.2 Functions for greatest-width integer types 277 | 278 | // 7.8.2.1 The imaxabs function 279 | #define imaxabs _abs64 280 | 281 | // 7.8.2.2 The imaxdiv function 282 | 283 | // This is modified version of div() function from Microsoft's div.c found 284 | // in %MSVC.NET%\crt\src\div.c 285 | #ifdef STATIC_IMAXDIV // [ 286 | static 287 | #else // STATIC_IMAXDIV ][ 288 | _inline 289 | #endif // STATIC_IMAXDIV ] 290 | imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) 291 | { 292 | imaxdiv_t result; 293 | 294 | result.quot = numer / denom; 295 | result.rem = numer % denom; 296 | 297 | if (numer < 0 && result.rem > 0) { 298 | // did division wrong; must fix up 299 | ++result.quot; 300 | result.rem -= denom; 301 | } 302 | 303 | return result; 304 | } 305 | 306 | // 7.8.2.3 The strtoimax and strtoumax functions 307 | #define strtoimax _strtoi64 308 | #define strtoumax _strtoui64 309 | 310 | // 7.8.2.4 The wcstoimax and wcstoumax functions 311 | #define wcstoimax _wcstoi64 312 | #define wcstoumax _wcstoui64 313 | 314 | #endif // _MSC_VER >= 1800 315 | 316 | #endif // _MSC_INTTYPES_H_ ] 317 | -------------------------------------------------------------------------------- /lib/rapidjson/internal/biginteger.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_BIGINTEGER_H_ 16 | #define RAPIDJSON_BIGINTEGER_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(_MSC_VER) && defined(_M_AMD64) 21 | #include // for _umul128 22 | #pragma intrinsic(_umul128) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | class BigInteger { 29 | public: 30 | typedef uint64_t Type; 31 | 32 | BigInteger(const BigInteger& rhs) : count_(rhs.count_) { 33 | std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type)); 34 | } 35 | 36 | explicit BigInteger(uint64_t u) : count_(1) { 37 | digits_[0] = u; 38 | } 39 | 40 | BigInteger(const char* decimals, size_t length) : count_(1) { 41 | RAPIDJSON_ASSERT(length > 0); 42 | digits_[0] = 0; 43 | size_t i = 0; 44 | const size_t kMaxDigitPerIteration = 19; // 2^64 = 18446744073709551616 > 10^19 45 | while (length >= kMaxDigitPerIteration) { 46 | AppendDecimal64(decimals + i, decimals + i + kMaxDigitPerIteration); 47 | length -= kMaxDigitPerIteration; 48 | i += kMaxDigitPerIteration; 49 | } 50 | 51 | if (length > 0) 52 | AppendDecimal64(decimals + i, decimals + i + length); 53 | } 54 | 55 | BigInteger& operator=(const BigInteger &rhs) 56 | { 57 | if (this != &rhs) { 58 | count_ = rhs.count_; 59 | std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type)); 60 | } 61 | return *this; 62 | } 63 | 64 | BigInteger& operator=(uint64_t u) { 65 | digits_[0] = u; 66 | count_ = 1; 67 | return *this; 68 | } 69 | 70 | BigInteger& operator+=(uint64_t u) { 71 | Type backup = digits_[0]; 72 | digits_[0] += u; 73 | for (size_t i = 0; i < count_ - 1; i++) { 74 | if (digits_[i] >= backup) 75 | return *this; // no carry 76 | backup = digits_[i + 1]; 77 | digits_[i + 1] += 1; 78 | } 79 | 80 | // Last carry 81 | if (digits_[count_ - 1] < backup) 82 | PushBack(1); 83 | 84 | return *this; 85 | } 86 | 87 | BigInteger& operator*=(uint64_t u) { 88 | if (u == 0) return *this = 0; 89 | if (u == 1) return *this; 90 | if (*this == 1) return *this = u; 91 | 92 | uint64_t k = 0; 93 | for (size_t i = 0; i < count_; i++) { 94 | uint64_t hi; 95 | digits_[i] = MulAdd64(digits_[i], u, k, &hi); 96 | k = hi; 97 | } 98 | 99 | if (k > 0) 100 | PushBack(k); 101 | 102 | return *this; 103 | } 104 | 105 | BigInteger& operator*=(uint32_t u) { 106 | if (u == 0) return *this = 0; 107 | if (u == 1) return *this; 108 | if (*this == 1) return *this = u; 109 | 110 | uint64_t k = 0; 111 | for (size_t i = 0; i < count_; i++) { 112 | const uint64_t c = digits_[i] >> 32; 113 | const uint64_t d = digits_[i] & 0xFFFFFFFF; 114 | const uint64_t uc = u * c; 115 | const uint64_t ud = u * d; 116 | const uint64_t p0 = ud + k; 117 | const uint64_t p1 = uc + (p0 >> 32); 118 | digits_[i] = (p0 & 0xFFFFFFFF) | (p1 << 32); 119 | k = p1 >> 32; 120 | } 121 | 122 | if (k > 0) 123 | PushBack(k); 124 | 125 | return *this; 126 | } 127 | 128 | BigInteger& operator<<=(size_t shift) { 129 | if (IsZero() || shift == 0) return *this; 130 | 131 | size_t offset = shift / kTypeBit; 132 | size_t interShift = shift % kTypeBit; 133 | RAPIDJSON_ASSERT(count_ + offset <= kCapacity); 134 | 135 | if (interShift == 0) { 136 | std::memmove(&digits_[count_ - 1 + offset], &digits_[count_ - 1], count_ * sizeof(Type)); 137 | count_ += offset; 138 | } 139 | else { 140 | digits_[count_] = 0; 141 | for (size_t i = count_; i > 0; i--) 142 | digits_[i + offset] = (digits_[i] << interShift) | (digits_[i - 1] >> (kTypeBit - interShift)); 143 | digits_[offset] = digits_[0] << interShift; 144 | count_ += offset; 145 | if (digits_[count_]) 146 | count_++; 147 | } 148 | 149 | std::memset(digits_, 0, offset * sizeof(Type)); 150 | 151 | return *this; 152 | } 153 | 154 | bool operator==(const BigInteger& rhs) const { 155 | return count_ == rhs.count_ && std::memcmp(digits_, rhs.digits_, count_ * sizeof(Type)) == 0; 156 | } 157 | 158 | bool operator==(const Type rhs) const { 159 | return count_ == 1 && digits_[0] == rhs; 160 | } 161 | 162 | BigInteger& MultiplyPow5(unsigned exp) { 163 | static const uint32_t kPow5[12] = { 164 | 5, 165 | 5 * 5, 166 | 5 * 5 * 5, 167 | 5 * 5 * 5 * 5, 168 | 5 * 5 * 5 * 5 * 5, 169 | 5 * 5 * 5 * 5 * 5 * 5, 170 | 5 * 5 * 5 * 5 * 5 * 5 * 5, 171 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 172 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 173 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 174 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 175 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 176 | }; 177 | if (exp == 0) return *this; 178 | for (; exp >= 27; exp -= 27) *this *= RAPIDJSON_UINT64_C2(0X6765C793, 0XFA10079D); // 5^27 179 | for (; exp >= 13; exp -= 13) *this *= static_cast(1220703125u); // 5^13 180 | if (exp > 0) *this *= kPow5[exp - 1]; 181 | return *this; 182 | } 183 | 184 | // Compute absolute difference of this and rhs. 185 | // Assume this != rhs 186 | bool Difference(const BigInteger& rhs, BigInteger* out) const { 187 | int cmp = Compare(rhs); 188 | RAPIDJSON_ASSERT(cmp != 0); 189 | const BigInteger *a, *b; // Makes a > b 190 | bool ret; 191 | if (cmp < 0) { a = &rhs; b = this; ret = true; } 192 | else { a = this; b = &rhs; ret = false; } 193 | 194 | Type borrow = 0; 195 | for (size_t i = 0; i < a->count_; i++) { 196 | Type d = a->digits_[i] - borrow; 197 | if (i < b->count_) 198 | d -= b->digits_[i]; 199 | borrow = (d > a->digits_[i]) ? 1 : 0; 200 | out->digits_[i] = d; 201 | if (d != 0) 202 | out->count_ = i + 1; 203 | } 204 | 205 | return ret; 206 | } 207 | 208 | int Compare(const BigInteger& rhs) const { 209 | if (count_ != rhs.count_) 210 | return count_ < rhs.count_ ? -1 : 1; 211 | 212 | for (size_t i = count_; i-- > 0;) 213 | if (digits_[i] != rhs.digits_[i]) 214 | return digits_[i] < rhs.digits_[i] ? -1 : 1; 215 | 216 | return 0; 217 | } 218 | 219 | size_t GetCount() const { return count_; } 220 | Type GetDigit(size_t index) const { RAPIDJSON_ASSERT(index < count_); return digits_[index]; } 221 | bool IsZero() const { return count_ == 1 && digits_[0] == 0; } 222 | 223 | private: 224 | void AppendDecimal64(const char* begin, const char* end) { 225 | uint64_t u = ParseUint64(begin, end); 226 | if (IsZero()) 227 | *this = u; 228 | else { 229 | unsigned exp = static_cast(end - begin); 230 | (MultiplyPow5(exp) <<= exp) += u; // *this = *this * 10^exp + u 231 | } 232 | } 233 | 234 | void PushBack(Type digit) { 235 | RAPIDJSON_ASSERT(count_ < kCapacity); 236 | digits_[count_++] = digit; 237 | } 238 | 239 | static uint64_t ParseUint64(const char* begin, const char* end) { 240 | uint64_t r = 0; 241 | for (const char* p = begin; p != end; ++p) { 242 | RAPIDJSON_ASSERT(*p >= '0' && *p <= '9'); 243 | r = r * 10u + static_cast(*p - '0'); 244 | } 245 | return r; 246 | } 247 | 248 | // Assume a * b + k < 2^128 249 | static uint64_t MulAdd64(uint64_t a, uint64_t b, uint64_t k, uint64_t* outHigh) { 250 | #if defined(_MSC_VER) && defined(_M_AMD64) 251 | uint64_t low = _umul128(a, b, outHigh) + k; 252 | if (low < k) 253 | (*outHigh)++; 254 | return low; 255 | #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__) 256 | __extension__ typedef unsigned __int128 uint128; 257 | uint128 p = static_cast(a) * static_cast(b); 258 | p += k; 259 | *outHigh = static_cast(p >> 64); 260 | return static_cast(p); 261 | #else 262 | const uint64_t a0 = a & 0xFFFFFFFF, a1 = a >> 32, b0 = b & 0xFFFFFFFF, b1 = b >> 32; 263 | uint64_t x0 = a0 * b0, x1 = a0 * b1, x2 = a1 * b0, x3 = a1 * b1; 264 | x1 += (x0 >> 32); // can't give carry 265 | x1 += x2; 266 | if (x1 < x2) 267 | x3 += (static_cast(1) << 32); 268 | uint64_t lo = (x1 << 32) + (x0 & 0xFFFFFFFF); 269 | uint64_t hi = x3 + (x1 >> 32); 270 | 271 | lo += k; 272 | if (lo < k) 273 | hi++; 274 | *outHigh = hi; 275 | return lo; 276 | #endif 277 | } 278 | 279 | static const size_t kBitCount = 3328; // 64bit * 54 > 10^1000 280 | static const size_t kCapacity = kBitCount / sizeof(Type); 281 | static const size_t kTypeBit = sizeof(Type) * 8; 282 | 283 | Type digits_[kCapacity]; 284 | size_t count_; 285 | }; 286 | 287 | } // namespace internal 288 | RAPIDJSON_NAMESPACE_END 289 | 290 | #endif // RAPIDJSON_BIGINTEGER_H_ 291 | -------------------------------------------------------------------------------- /lib/rapidjson/msinttypes/stdint.h: -------------------------------------------------------------------------------- 1 | // ISO C9x compliant stdint.h for Microsoft Visual Studio 2 | // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 3 | // 4 | // Copyright (c) 2006-2013 Alexander Chemeris 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright 13 | // notice, this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // 3. Neither the name of the product nor the names of its contributors may 17 | // be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 22 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 23 | // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | // 31 | /////////////////////////////////////////////////////////////////////////////// 32 | 33 | // The above software in this distribution may have been modified by 34 | // THL A29 Limited ("Tencent Modifications"). 35 | // All Tencent Modifications are Copyright (C) 2015 THL A29 Limited. 36 | 37 | #ifndef _MSC_VER // [ 38 | #error "Use this header only with Microsoft Visual C++ compilers!" 39 | #endif // _MSC_VER ] 40 | 41 | #ifndef _MSC_STDINT_H_ // [ 42 | #define _MSC_STDINT_H_ 43 | 44 | #if _MSC_VER > 1000 45 | #pragma once 46 | #endif 47 | 48 | // miloyip: Originally Visual Studio 2010 uses its own stdint.h. However it generates warning with INT64_C(), so change to use this file for vs2010. 49 | #if _MSC_VER >= 1600 // [ 50 | #include 51 | 52 | #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 53 | 54 | #undef INT8_C 55 | #undef INT16_C 56 | #undef INT32_C 57 | #undef INT64_C 58 | #undef UINT8_C 59 | #undef UINT16_C 60 | #undef UINT32_C 61 | #undef UINT64_C 62 | 63 | // 7.18.4.1 Macros for minimum-width integer constants 64 | 65 | #define INT8_C(val) val##i8 66 | #define INT16_C(val) val##i16 67 | #define INT32_C(val) val##i32 68 | #define INT64_C(val) val##i64 69 | 70 | #define UINT8_C(val) val##ui8 71 | #define UINT16_C(val) val##ui16 72 | #define UINT32_C(val) val##ui32 73 | #define UINT64_C(val) val##ui64 74 | 75 | // 7.18.4.2 Macros for greatest-width integer constants 76 | // These #ifndef's are needed to prevent collisions with . 77 | // Check out Issue 9 for the details. 78 | #ifndef INTMAX_C // [ 79 | # define INTMAX_C INT64_C 80 | #endif // INTMAX_C ] 81 | #ifndef UINTMAX_C // [ 82 | # define UINTMAX_C UINT64_C 83 | #endif // UINTMAX_C ] 84 | 85 | #endif // __STDC_CONSTANT_MACROS ] 86 | 87 | #else // ] _MSC_VER >= 1700 [ 88 | 89 | #include 90 | 91 | // For Visual Studio 6 in C++ mode and for many Visual Studio versions when 92 | // compiling for ARM we have to wrap include with 'extern "C++" {}' 93 | // or compiler would give many errors like this: 94 | // error C2733: second C linkage of overloaded function 'wmemchr' not allowed 95 | #if defined(__cplusplus) && !defined(_M_ARM) 96 | extern "C" { 97 | #endif 98 | # include 99 | #if defined(__cplusplus) && !defined(_M_ARM) 100 | } 101 | #endif 102 | 103 | // Define _W64 macros to mark types changing their size, like intptr_t. 104 | #ifndef _W64 105 | # if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 106 | # define _W64 __w64 107 | # else 108 | # define _W64 109 | # endif 110 | #endif 111 | 112 | 113 | // 7.18.1 Integer types 114 | 115 | // 7.18.1.1 Exact-width integer types 116 | 117 | // Visual Studio 6 and Embedded Visual C++ 4 doesn't 118 | // realize that, e.g. char has the same size as __int8 119 | // so we give up on __intX for them. 120 | #if (_MSC_VER < 1300) 121 | typedef signed char int8_t; 122 | typedef signed short int16_t; 123 | typedef signed int int32_t; 124 | typedef unsigned char uint8_t; 125 | typedef unsigned short uint16_t; 126 | typedef unsigned int uint32_t; 127 | #else 128 | typedef signed __int8 int8_t; 129 | typedef signed __int16 int16_t; 130 | typedef signed __int32 int32_t; 131 | typedef unsigned __int8 uint8_t; 132 | typedef unsigned __int16 uint16_t; 133 | typedef unsigned __int32 uint32_t; 134 | #endif 135 | typedef signed __int64 int64_t; 136 | typedef unsigned __int64 uint64_t; 137 | 138 | 139 | // 7.18.1.2 Minimum-width integer types 140 | typedef int8_t int_least8_t; 141 | typedef int16_t int_least16_t; 142 | typedef int32_t int_least32_t; 143 | typedef int64_t int_least64_t; 144 | typedef uint8_t uint_least8_t; 145 | typedef uint16_t uint_least16_t; 146 | typedef uint32_t uint_least32_t; 147 | typedef uint64_t uint_least64_t; 148 | 149 | // 7.18.1.3 Fastest minimum-width integer types 150 | typedef int8_t int_fast8_t; 151 | typedef int16_t int_fast16_t; 152 | typedef int32_t int_fast32_t; 153 | typedef int64_t int_fast64_t; 154 | typedef uint8_t uint_fast8_t; 155 | typedef uint16_t uint_fast16_t; 156 | typedef uint32_t uint_fast32_t; 157 | typedef uint64_t uint_fast64_t; 158 | 159 | // 7.18.1.4 Integer types capable of holding object pointers 160 | #ifdef _WIN64 // [ 161 | typedef signed __int64 intptr_t; 162 | typedef unsigned __int64 uintptr_t; 163 | #else // _WIN64 ][ 164 | typedef _W64 signed int intptr_t; 165 | typedef _W64 unsigned int uintptr_t; 166 | #endif // _WIN64 ] 167 | 168 | // 7.18.1.5 Greatest-width integer types 169 | typedef int64_t intmax_t; 170 | typedef uint64_t uintmax_t; 171 | 172 | 173 | // 7.18.2 Limits of specified-width integer types 174 | 175 | #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 176 | 177 | // 7.18.2.1 Limits of exact-width integer types 178 | #define INT8_MIN ((int8_t)_I8_MIN) 179 | #define INT8_MAX _I8_MAX 180 | #define INT16_MIN ((int16_t)_I16_MIN) 181 | #define INT16_MAX _I16_MAX 182 | #define INT32_MIN ((int32_t)_I32_MIN) 183 | #define INT32_MAX _I32_MAX 184 | #define INT64_MIN ((int64_t)_I64_MIN) 185 | #define INT64_MAX _I64_MAX 186 | #define UINT8_MAX _UI8_MAX 187 | #define UINT16_MAX _UI16_MAX 188 | #define UINT32_MAX _UI32_MAX 189 | #define UINT64_MAX _UI64_MAX 190 | 191 | // 7.18.2.2 Limits of minimum-width integer types 192 | #define INT_LEAST8_MIN INT8_MIN 193 | #define INT_LEAST8_MAX INT8_MAX 194 | #define INT_LEAST16_MIN INT16_MIN 195 | #define INT_LEAST16_MAX INT16_MAX 196 | #define INT_LEAST32_MIN INT32_MIN 197 | #define INT_LEAST32_MAX INT32_MAX 198 | #define INT_LEAST64_MIN INT64_MIN 199 | #define INT_LEAST64_MAX INT64_MAX 200 | #define UINT_LEAST8_MAX UINT8_MAX 201 | #define UINT_LEAST16_MAX UINT16_MAX 202 | #define UINT_LEAST32_MAX UINT32_MAX 203 | #define UINT_LEAST64_MAX UINT64_MAX 204 | 205 | // 7.18.2.3 Limits of fastest minimum-width integer types 206 | #define INT_FAST8_MIN INT8_MIN 207 | #define INT_FAST8_MAX INT8_MAX 208 | #define INT_FAST16_MIN INT16_MIN 209 | #define INT_FAST16_MAX INT16_MAX 210 | #define INT_FAST32_MIN INT32_MIN 211 | #define INT_FAST32_MAX INT32_MAX 212 | #define INT_FAST64_MIN INT64_MIN 213 | #define INT_FAST64_MAX INT64_MAX 214 | #define UINT_FAST8_MAX UINT8_MAX 215 | #define UINT_FAST16_MAX UINT16_MAX 216 | #define UINT_FAST32_MAX UINT32_MAX 217 | #define UINT_FAST64_MAX UINT64_MAX 218 | 219 | // 7.18.2.4 Limits of integer types capable of holding object pointers 220 | #ifdef _WIN64 // [ 221 | # define INTPTR_MIN INT64_MIN 222 | # define INTPTR_MAX INT64_MAX 223 | # define UINTPTR_MAX UINT64_MAX 224 | #else // _WIN64 ][ 225 | # define INTPTR_MIN INT32_MIN 226 | # define INTPTR_MAX INT32_MAX 227 | # define UINTPTR_MAX UINT32_MAX 228 | #endif // _WIN64 ] 229 | 230 | // 7.18.2.5 Limits of greatest-width integer types 231 | #define INTMAX_MIN INT64_MIN 232 | #define INTMAX_MAX INT64_MAX 233 | #define UINTMAX_MAX UINT64_MAX 234 | 235 | // 7.18.3 Limits of other integer types 236 | 237 | #ifdef _WIN64 // [ 238 | # define PTRDIFF_MIN _I64_MIN 239 | # define PTRDIFF_MAX _I64_MAX 240 | #else // _WIN64 ][ 241 | # define PTRDIFF_MIN _I32_MIN 242 | # define PTRDIFF_MAX _I32_MAX 243 | #endif // _WIN64 ] 244 | 245 | #define SIG_ATOMIC_MIN INT_MIN 246 | #define SIG_ATOMIC_MAX INT_MAX 247 | 248 | #ifndef SIZE_MAX // [ 249 | # ifdef _WIN64 // [ 250 | # define SIZE_MAX _UI64_MAX 251 | # else // _WIN64 ][ 252 | # define SIZE_MAX _UI32_MAX 253 | # endif // _WIN64 ] 254 | #endif // SIZE_MAX ] 255 | 256 | // WCHAR_MIN and WCHAR_MAX are also defined in 257 | #ifndef WCHAR_MIN // [ 258 | # define WCHAR_MIN 0 259 | #endif // WCHAR_MIN ] 260 | #ifndef WCHAR_MAX // [ 261 | # define WCHAR_MAX _UI16_MAX 262 | #endif // WCHAR_MAX ] 263 | 264 | #define WINT_MIN 0 265 | #define WINT_MAX _UI16_MAX 266 | 267 | #endif // __STDC_LIMIT_MACROS ] 268 | 269 | 270 | // 7.18.4 Limits of other integer types 271 | 272 | #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 273 | 274 | // 7.18.4.1 Macros for minimum-width integer constants 275 | 276 | #define INT8_C(val) val##i8 277 | #define INT16_C(val) val##i16 278 | #define INT32_C(val) val##i32 279 | #define INT64_C(val) val##i64 280 | 281 | #define UINT8_C(val) val##ui8 282 | #define UINT16_C(val) val##ui16 283 | #define UINT32_C(val) val##ui32 284 | #define UINT64_C(val) val##ui64 285 | 286 | // 7.18.4.2 Macros for greatest-width integer constants 287 | // These #ifndef's are needed to prevent collisions with . 288 | // Check out Issue 9 for the details. 289 | #ifndef INTMAX_C // [ 290 | # define INTMAX_C INT64_C 291 | #endif // INTMAX_C ] 292 | #ifndef UINTMAX_C // [ 293 | # define UINTMAX_C UINT64_C 294 | #endif // UINTMAX_C ] 295 | 296 | #endif // __STDC_CONSTANT_MACROS ] 297 | 298 | #endif // _MSC_VER >= 1600 ] 299 | 300 | #endif // _MSC_STDINT_H_ ] 301 | --------------------------------------------------------------------------------