Skip to content
This repository was archived by the owner on Nov 16, 2020. It is now read-only.

Commit 3b89510

Browse files
author
Alex Chi
committed
[CODE] add a batch file to regenerate the code file for UE4
1 parent 628162f commit 3b89510

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
libprotobuf for [UE4][]
2+
=====
3+
4+
Use the google's protobuf library as the third party in [Unreal Engine 4][].
5+
6+
7+
8+
[UE4]: https://www.unrealengine.com/
9+
[Unreal Engine 4]: https://www.unrealengine.com/

libprotobuf.Build.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
1+
// Copyright 2016 Code 4 Game. All Rights Reserved.
22

33
using UnrealBuildTool;
44

regenerateforue4.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from datetime import *
2+
import os
3+
import sys
4+
5+
comment = '// Added for UE4 in {0}(UTC)'.format(datetime.utcnow())
6+
include_allow_header = '#include "AllowWindowsPlatformTypes.h"'
7+
include_hide_header = '#include "HideWindowsPlatformTypes.h"'
8+
9+
def Check(_CodeFile):
10+
if (os.path.isfile(_CodeFile) is False):
11+
print "Can't find the code file!!!"
12+
return False
13+
14+
code_file = open(_CodeFile, 'r')
15+
if (code_file is None):
16+
print "Failed to read the code file!!!"
17+
return False
18+
code_lines = code_file.readlines()
19+
code_file.close()
20+
21+
for line in code_lines[:10]:
22+
if (line.find(include_allow_header) < 0 and line.find(include_hide_header) < 0):
23+
continue
24+
print "Already was regenerated?"
25+
return False
26+
return True
27+
28+
def Generate(_CodeFile):
29+
if (Check(_CodeFile) is False):
30+
print "Failed to check the code file!!!"
31+
return
32+
33+
if (os.path.isfile(_CodeFile) is False):
34+
print "Can't find the code file!!!"
35+
return
36+
37+
code_file = open(_CodeFile, 'r')
38+
if (code_file is None):
39+
print "Failed to read the code file!!!"
40+
return
41+
code_lines = code_file.readlines()
42+
code_file.close()
43+
44+
code_file = open(_CodeFile, 'w')
45+
if (code_file is None):
46+
print "Failed to write the code file!!!"
47+
return
48+
meet_first_include = False
49+
meet_last_include = False
50+
for line in code_lines:
51+
if (meet_first_include is False and line[0:10] == "#include \""):
52+
code_file.write('\n{0} {1}\n\n'.format(include_allow_header, comment))
53+
meet_first_include = True
54+
code_file.write(line)
55+
if (meet_last_include is False and line[:len(line) - 1] == "// @@protoc_insertion_point(includes)"):
56+
code_file.write('\n{0} {1}\n\n'.format(include_hide_header, comment))
57+
meet_last_include = True
58+
code_file.close()
59+
if (meet_first_include is False):
60+
print "Can't add the allow header!!!"
61+
if (meet_last_include is False):
62+
print "Can't add the hide header!!!"
63+
if (meet_first_include and meet_last_include):
64+
print "Success to regenerate the code for UE4"
65+
66+
if len(sys.argv) <= 1:
67+
print "Usage: python regenerateforue4.py `code file`"
68+
else:
69+
Generate(sys.argv[1])

0 commit comments

Comments
 (0)