@@ -63,11 +63,15 @@ namespace tsom
6363 m_downloadManager.Cancel ();
6464 }
6565
66- void UpdaterAppComponent::DownloadAndUpdate (const UpdateInfo& updateInfo, bool downloadAssets, bool downloadBinaries)
66+ void UpdaterAppComponent::DownloadAndUpdate (const UpdateInfo& updateInfo, bool downloadAssets, bool downloadBinaries, bool downloadUpdater, bool startUpdateWhenReady )
6767 {
6868 assert (downloadAssets || downloadBinaries);
69+ assert (!startUpdateWhenReady || downloadUpdater);
70+
71+ // just in case
72+ m_activeDownloads.clear ();
73+ m_updaterDownload.reset ();
6974
70- m_activeDownloads.clear (); // < just in case
7175 auto QueueDownload = [&](std::string_view filename, const UpdateInfo::DownloadInfo& info, bool isExecutable = false )
7276 {
7377 auto download = m_downloadManager.QueueDownload (Nz::Utf8Path (filename), info.downloadUrl , info.size , info.sha256 , false , isExecutable);
@@ -82,7 +86,8 @@ namespace tsom
8286 if (downloadBinaries)
8387 m_updateArchives.push_back (QueueDownload (" autoupdate_binaries" , updateInfo.binaries ));
8488
85- m_updaterDownload = QueueDownload (" this_updater_of_mine" , updateInfo.updater , true );
89+ if (downloadUpdater)
90+ m_updaterDownload = QueueDownload (" this_updater_of_mine" , updateInfo.updater , true );
8691
8792 for (auto & downloadPtr : m_activeDownloads)
8893 {
@@ -96,19 +101,27 @@ namespace tsom
96101 UpdateProgression ();
97102 });
98103
99- downloadPtr->OnDownloadFinished .Connect ([this ](const DownloadManager::Download&)
104+ downloadPtr->OnDownloadFinished .Connect ([this , startUpdateWhenReady ](const DownloadManager::Download&)
100105 {
101106 if (!m_downloadManager.HasDownloadInProgress ())
102- StartUpdaterAndQuit ();
107+ {
108+ OnUpdateReady ();
109+ if (startUpdateWhenReady)
110+ StartUpdaterAndQuit ();
111+ }
103112 });
104113 }
105114
106115 // Can happen if all files were already downloaded
107116 if (!m_downloadManager.HasDownloadInProgress ())
108- StartUpdaterAndQuit ();
117+ {
118+ OnUpdateReady ();
119+ if (startUpdateWhenReady)
120+ StartUpdaterAndQuit ();
121+ }
109122 }
110123
111- void UpdaterAppComponent::FetchLastVersion (std::function<void (Nz::Result<UpdateInfo, std::string>&& updateInfo)>&& callback)
124+ void UpdaterAppComponent::FetchLastVersion (bool server, std::function<void (Nz::Result<UpdateInfo, std::string>&& updateInfo)>&& callback)
112125 {
113126 auto * webService = GetApp ().TryGetComponent <Nz::WebServiceAppComponent>();
114127 if (!webService)
@@ -117,10 +130,10 @@ namespace tsom
117130 return ;
118131 }
119132
120- webService->QueueRequest ([&](Nz::WebRequest& request)
133+ webService->QueueRequest ([&, server ](Nz::WebRequest& request)
121134 {
122135 request.SetMethod (Nz::WebRequestMethod::Get);
123- request.SetURL (fmt::format (" {}/game_version?platform={}" , m_configFile.GetStringValue (" Api.Url" ), BuildConfig ));
136+ request.SetURL (fmt::format (" {}/game_version?platform={}{}_{} " , m_configFile.GetStringValue (" Api.Url" ), BuildPlatform, server ? " -server " : " " , BuildArch ));
124137 request.SetServiceName (" TSOM Version Check" );
125138 request.SetResultCallback ([cb = std::move (callback)](Nz::WebRequestResult&& result)
126139 {
@@ -158,35 +171,41 @@ namespace tsom
158171 {
159172 OnUpdateStarting ();
160173
161- Nz::Pid pid = Nz::Process::GetCurrentPid ();
174+ if (m_updaterDownload)
175+ {
176+ Nz::Pid pid = Nz::Process::GetCurrentPid ();
162177
163- std::vector<std::string> args;
164- args.push_back (std::to_string ( pid)); // pid to wait before starting update
178+ std::vector<std::string> args;
179+ args.push_back (fmt::format ( " --pid={} " , pid)); // pid to wait before starting update
165180
166- // TODO: Add a way to retrieve executable name (or use argv[0]?)
167- #ifdef NAZARA_PLATFORM_WINDOWS
168- args.push_back (" ThisSpaceOfMine.exe" );
169- #else
170- args.push_back (" ./ThisSpaceOfMine" );
171- #endif
181+ for (auto & downloadPtr : m_updateArchives)
182+ {
183+ args.push_back (" --archive" );
184+ args.push_back (Nz::PathToString (downloadPtr->filepath ));
185+ }
172186
173- for (auto & downloadPtr : m_updateArchives)
174- args.push_back (Nz::PathToString (downloadPtr->filepath ));
187+ std::span<const char *> applicationArgs = GetApp ().GetArgs ();
175188
176- Nz::Result updater = Nz::Process::SpawnDetached (m_updaterDownload->filepath , args);
177- if (!updater)
178- {
179- fmt::print (fg (fmt::color::red), " failed to start autoupdater process: {0}\n " , updater.GetError ());
180- return ;
189+ args.push_back (" --executable" );
190+ args.push_back (applicationArgs[0 ]);
191+
192+ for (std::size_t i = 1 ; i < applicationArgs.size (); ++i)
193+ {
194+ args.push_back (" --arg" );
195+ args.push_back (applicationArgs[i]);
196+ }
197+
198+ Nz::Result updater = Nz::Process::SpawnDetached (m_updaterDownload->filepath , args);
199+ if (!updater)
200+ {
201+ fmt::print (fg (fmt::color::red), " failed to start autoupdater process: {0}\n " , updater.GetError ());
202+ return ;
203+ }
181204 }
182205
183206 GetApp ().Quit ();
184207 }
185208
186- void UpdaterAppComponent::Update (Nz::Time elapsedTime)
187- {
188- }
189-
190209 void UpdaterAppComponent::UpdateProgression ()
191210 {
192211 std::size_t activeDownloadCount = 0 ;
0 commit comments