FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Source.Python/src/loader/updater.cpp at v742 · Source-Python-Dev-Team/Source.Python · GitHub
Source-Python-Dev-Team
Source.Python
Repository navigation
Code
Issues
9
(9)
Pull requests
11
(11)
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
Source.Python
/
src
/
loader
/
updater.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
116 lines (97 loc) · 3.88 KB
Breadcrumbs
Source.Python
/
src
/
loader
/
updater.cpp
Copy path
File metadata and controls
116 lines (97 loc) · 3.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
*
* =============================================================================
* Source Python
* Copyright (C) 2012-2018 Source Python Development Team. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the Source Python Team gives you permission
* to link the code of this program (as well as its derivative works) to
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, the Source.Python
* Development Team grants this exception to all derivative works.
*/
//
---------------------------------------------------------------------------------
//
Includes
//
---------------------------------------------------------------------------------
//
Source.Python
#
include
"
updater.h
"
#
include
"
definitions.h
"
//
Boost
#
include
"
boost/filesystem.hpp
"
namespace
bfs
=
boost::filesystem;
//
SDK
#
include
"
eiface.h
"
//
---------------------------------------------------------------------------------
//
Declarations
//
---------------------------------------------------------------------------------
extern
IVEngineServer* engine;
//
---------------------------------------------------------------------------------
//
Functions
//
---------------------------------------------------------------------------------
bool
UpdateAvailable
()
{
DevMsg
(
1
,
MSG_PREFIX
"
Checking if update stage 2 can be applied...
"
);
char
szGameDir[
MAX_PATH_LENGTH
];
engine->
GetGameDir
(szGameDir,
MAX_PATH_LENGTH
);
bfs::path updateDir =
bfs::path
(szGameDir) /
SP_UPDATE_PATH
;
bool
result =
bfs::is_directory
(updateDir) && !
bfs::is_empty
(updateDir);
DevMsg
(
1
,
"
%s.
\n
"
, result ?
"
Yes
"
:
"
No
"
);
return
result;
}
static
void
DeleteDir
(
const
bfs::path& dir)
{
DevMsg
(
1
,
MSG_PREFIX
"
Deleting %s...
\n
"
, dir.
string
().
c_str
());
bfs::remove_all
(dir);
}
static
void
MergeDirectories
(
const
bfs::path& src,
const
bfs::path& dst)
{
if
(
bfs::is_directory
(src)) {
bfs::create_directories
(dst);
bfs::directory_iterator end_iter;
for
(bfs::directory_iterator
iter
(src); iter != end_iter; ++iter)
{
MergeDirectories
(iter->
path
(), dst/iter->
path
().
filename
());
}
}
else
if
(
bfs::is_regular_file
(src))
{
DevMsg
(
5
,
MSG_PREFIX
"
Merging %s into %s...
\n
"
, src.
string
().
c_str
(), dst.
string
().
c_str
());
bfs::rename
(src, dst);
}
else
{
Msg
(
MSG_PREFIX
"
%s is not a file or directory. Doing nothing...
\n
"
, dst.
string
().
c_str
());
}
}
void
ApplyUpdateStage2
()
{
Msg
(
MSG_PREFIX
"
Applying update stage 2...
\n
"
);
char
szGameDir[
MAX_PATH_LENGTH
];
engine->
GetGameDir
(szGameDir,
MAX_PATH_LENGTH
);
//
Delete old directories
DeleteDir
(
bfs::path
(szGameDir) /
SP_PACKAGE_PATH
);
DeleteDir
(
bfs::path
(szGameDir) /
SITE_PACKAGE_PATH
);
DeleteDir
(
bfs::path
(szGameDir) /
SP_DATA_PATH
);
DeleteDir
(
bfs::path
(szGameDir) /
SP_DOCS_PATH
);
DeleteDir
(
bfs::path
(szGameDir) /
PYTHON3_PATH
);
//
Move files from update dir to real dir
bfs::path updateDir =
bfs::path
(szGameDir) /
SP_UPDATE_PATH
;
DevMsg
(
1
,
MSG_PREFIX
"
Merging
\"
%s
\"
into
\"
%s
\"
...
\n
"
, updateDir.
string
().
c_str
(), szGameDir);
MergeDirectories
(updateDir, szGameDir);
//
Delete update dir, because it now contains a bunch of empty directories
DeleteDir
(updateDir);
Msg
(
MSG_PREFIX
"
Stage 2 has been applied.
\n
"
);
}
Back
|
FazBrowse Home
|
New Git URL