1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifdef RYZOM_BG_DOWNLOADER
21 #ifndef CL_BG_DOWNLOADER_ACCESS
22 #define CL_BG_DOWNLOADER_ACCESS
24 #include "nel/misc/singleton.h"
25 #include "nel/misc/ucstring.h" // OLD
26 #include "nel/misc/inter_window_msg_queue.h"
27 #include "nel/misc/co_task.h"
29 #include "game_share/bg_downloader_msg.h"
30 #include "game_share/bnp_patch.h"
32 // communication with bg downloader
33 class CBGDownloaderAccess
: public NLMISC::CSingleton
<CBGDownloaderAccess
>
36 CBGDownloaderAccess();
37 ~CBGDownloaderAccess();
38 // Init the background downloader access.
42 void startTask(const BGDownloader::CTaskDesc
&taskDesc
, const std::string
&commandLine
, bool showDownloader
);
43 bool isTaskEnded(BGDownloader::TTaskResult
&result
, ucstring
&errorMsg
) const; // OLD
44 // The following flag will be true after a 'patch' task has been completed successfully
45 bool getPatchCompletionFlag(bool clearFlag
);
47 BGDownloader::TTaskResult
getLastTaskResult() const { return _TaskResult
; }
48 bool mustLaunchBatFile() const { return _MustLaunchBatFile
; }
50 // Valid after a task has ended. If this was a check task, then contain a bitfield indexed by
51 // BGDownloader::TDownloadID that indicate the part that need to be patched
52 uint32
getAvailablePatchs() const { return _AvailablePatchs
; }
53 void resumeBackgroundDownload();
55 void update(); // call this at each frame to update the download process
56 // Get last displayed message by the background downloader
57 const ucstring
&getCurrentMessage() const { return _CurrentMessage
; } // OLD
58 uint32
getCurrentFilesToGet() const { return _CurrentFilesToGet
; }
59 uint32
getTotalFilesToGet() const { return _TotalFilesToGet
; }
61 uint32
getPatchingSize() const { return _PatchingSize
; }
62 uint32
getTotalSize() const { return _TotalSize
; }
63 float getCurrentFileProgress() const { return _CurrentFileProgress
; }
65 void showDownloader();
66 void hideDownloader();
69 BGDownloader::TThreadPriority
getDownloadThreadPriority() const { return _DownloadThreadPriority
; }
70 bool isDownloaderUIFrozen() const { return _FrozenUI
; }
71 void requestDownloadThreadPriority(BGDownloader::TThreadPriority newPriority
, bool freezeUI
);
73 const ucstring
&getLastErrorMessage() const { return _ErrorMsg
; } // OLD
76 enum TState
{ State_Idle
, State_Patching
, State_Finished
};
79 ucstring _CurrentMessage
; // OLD
81 NLMISC::CInterWindowMsgQueue _DownloaderMsgQueue
;
83 ucstring _ErrorMsg
; // OLD
84 std::string _CommandLine
;
85 BGDownloader::TTaskResult _TaskResult
;
86 uint32 _AvailablePatchs
;
87 BGDownloader::CTaskDesc _WantedTask
;
88 uint32 _CurrentFilesToGet
;
89 uint32 _TotalFilesToGet
;
92 float _CurrentFileProgress
;
93 CProductDescriptionForClient _DescFile
;
94 BGDownloader::TThreadPriority _DownloadThreadPriority
;
95 void *_RyzomInstPIDPtr
;
98 bool _MustLaunchBatFile
;
99 bool _PatchCompletionFlag
;
100 bool _WaitBalloonDisplay
;
101 // The download task, implemented as a coroutine
102 class CDownloadCoTask
: public NLMISC::CCoTask
105 CBGDownloaderAccess
*Parent
;
106 BGDownloader::TDownloadID DownloadID
;
109 void restartDownloader();
110 void createDownloaderProcess();
111 void waitMsg(BGDownloader::TMsgType wantedMsgType
, NLMISC::CMemStream
&msg
, NLMISC::TTime timeOutInMs
= 6000000);
112 void sendMsg(NLMISC::CMemStream
&msg
);
113 void sendSimpleMsg(BGDownloader::TMsgType msgType
);
114 bool defaultMessageHandling(BGDownloader::TMsgType msgType
, NLMISC::CMemStream
&msg
);
115 void setDownloaderMode(BGDownloader::TDownloaderMode mode
);
116 void setDownloaderVerbosity(bool verbose
);
117 bool isDownloaderProcessRunning();
118 BGDownloader::CTaskDesc
getDownloaderState();
119 void doTask(const BGDownloader::CTaskDesc
&taskDesc
); // return value may indicate 'idle' or 'want reboot'
121 void startTask(const BGDownloader::CTaskDesc
&taskDesc
);
123 void checkDownloaderAlive();
124 void yieldDownload(); // same as yield, but also handle the isTerminationRequested() case
125 void shutdownDownloader();
126 void getTaskResult(BGDownloader::TTaskResult
&result
,
127 uint32
&availablePatchs
,
128 bool &mustLaunchBatFile
,
129 ucstring
&errorMsg
// OLD
132 BGDownloader::TDownloaderMode
getDownloaderMode();
134 CDownloadCoTask
*_DownloadCoTask
;
135 friend class CDownloadCoTask
;
137 void setDownloaderVerbosity(bool verbose
);
138 void clearCurrentMessage();
139 void sendSimpleMsg(BGDownloader::TMsgType msgType
);
140 void resetDownloadTask();
144 bool isBGDownloadEnabled();
147 // helpers to pause / unpause downloader & retore its previous state
148 void pauseBGDownloader();
149 void unpauseBGDownloader();