Skip to content

Commit

Permalink
Port 1.8 scripting changes to 1.7.10
Browse files Browse the repository at this point in the history
  • Loading branch information
StellaArtois committed Nov 26, 2014
1 parent 71989be commit 0f69a3b
Show file tree
Hide file tree
Showing 14 changed files with 313 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.*.swp
/logs/
/*.pyc
/*mcp*/
/mcp9*/
.idea/
*.iml
releases/
Expand Down
3 changes: 2 additions & 1 deletion applychanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil, fnmatch
import subprocess, shlex
from optparse import OptionParser
from minecriftversion import mc_version, minecrift_version_num, minecrift_build, of_file_extension, of_file_md5, mcp_version

base_dir = os.path.dirname(os.path.abspath(__file__))

Expand Down Expand Up @@ -80,4 +81,4 @@ def applychanges(mcp_dir):
elif os.path.isfile(os.path.join('..', 'runtime', 'commands.py')):
applychanges(os.path.abspath('..'))
else:
applychanges(os.path.abspath('mcp908'))
applychanges(os.path.abspath(mcp_version))
69 changes: 60 additions & 9 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import shutil, tempfile,zipfile, fnmatch
from optparse import OptionParser
import subprocess, shlex

from tempfile import mkstemp
from shutil import move
from os import remove, close
from install import download_deps, download_native, download_file, mkdir_p

mc_ver ="1.7.10"
from minecriftversion import mc_version, of_file_name, of_json_name, minecrift_version_num, minecrift_build, of_file_extension, of_file_md5, mcp_version, forge_version

try:
WindowsError
Expand Down Expand Up @@ -45,13 +46,13 @@ def process_json( addon, version ):
json_id = "minecrift-"+version+addon
lib_id = "com.mtbs3d:minecrift:"+version
time = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S-05:00")
with open(os.path.join("installer",mc_ver+addon+".json"),"rb") as f:
with open(os.path.join("installer",mc_version+addon+".json"),"rb") as f:
json_obj = json.load(f)
json_obj["id"] = json_id
json_obj["time"] = time
json_obj["releaseTime"] = time
json_obj["libraries"].insert(0,{"name":lib_id}) #Insert at beginning
json_obj["libraries"].append({"name":"net.minecraft:Minecraft:"+mc_ver}) #Insert at end
json_obj["libraries"].append({"name":"net.minecraft:Minecraft:"+mc_version}) #Insert at end
return json.dumps( json_obj, indent=1 )

def create_install(mcp_dir):
Expand All @@ -78,20 +79,51 @@ def create_install(mcp_dir):
elif os.getenv("BUILD_NUMBER"):
version = "b"+os.getenv("BUILD_NUMBER")
else:
version = "PRE4"
version = minecrift_build

version = mc_ver+"-"+version
version = minecrift_version_num+"-"+version

# Replace version info in installer.java
print "Updating installer versions..."
installer_java_file = os.path.join("installer","Installer.java")
replacelineinfile( installer_java_file, "private static final String MINECRAFT_VERSION", " private static final String MINECRAFT_VERSION = \"%s\";\n" % mc_version );
replacelineinfile( installer_java_file, "private static final String MC_VERSION", " private static final String MC_VERSION = \"%s\";\n" % minecrift_version_num );
replacelineinfile( installer_java_file, "private static final String OF_FILE_NAME", " private static final String OF_FILE_NAME = \"%s\";\n" % of_file_name );
replacelineinfile( installer_java_file, "private static final String OF_JSON_NAME", " private static final String OF_JSON_NAME = \"%s\";\n" % of_json_name );
replacelineinfile( installer_java_file, "private static final String OF_MD5", " private static final String OF_MD5 = \"%s\";\n" % of_file_md5 );
replacelineinfile( installer_java_file, "private static final String OF_VERSION_EXT", " private static final String OF_VERSION_EXT = \"%s\";\n" % of_file_extension );
replacelineinfile( installer_java_file, "private static final String FORGE_VERSION", " private static final String FORGE_VERSION = \"%s\";\n" % forge_version );

# Build installer.java
print "Recompiling Installer.java..."
subprocess.Popen(
cmdsplit("javac \"%s\"" % os.path.join(base_dir,installer_java_file)),
cwd=os.path.join(base_dir,"installer"),
bufsize=-1).communicate()

artifact_id = "minecrift-"+version
installer_id = artifact_id+"-installer"
installer = os.path.join( installer_id+".jar" )
shutil.copy( os.path.join("installer","installer.jar"), installer )
with zipfile.ZipFile( installer,'a', zipfile.ZIP_DEFLATED) as install_out: #append to installer.jar

# Add newly compiled class files
for afile in os.listdir("installer"):
if os.path.isfile(os.path.join("installer",afile)) and afile.endswith('.class'):
print "Adding %s..." % afile
install_out.write(os.path.join("installer",afile), afile)

# Add json files
install_out.writestr( "version.json", process_json("", version))
install_out.writestr( "version-forge.json", process_json("-forge", version))
install_out.writestr( "version-nohydra.json", process_json("-nohydra", version))
install_out.writestr( "version-forge-nohydra.json", process_json("-forge-nohydra", version))

# Add version jar - this contains all the changed files (effectively minecrift.jar). A mix
# of obfuscated and non-obfuscated files.
install_out.writestr( "version.jar", in_mem_zip.read() )

# Add the version info
install_out.writestr( "version", artifact_id+":"+version )

print("Creating Installer exe...")
Expand All @@ -106,12 +138,31 @@ def create_install(mcp_dir):
bufsize=-1).communicate()
os.unlink( "launch4j.xml" )

def replacelineinfile(file_path, pattern, subst):
#Create temp file
fh, abs_path = mkstemp()
new_file = open(abs_path,'w')
old_file = open(file_path)
for line in old_file:
if pattern in line:
new_file.write(subst)
else:
new_file.write(line)
#close temp file
new_file.close()
close(fh)
old_file.close()
#Remove original file
remove(file_path)
#Move new file
move(abs_path, file_path)

def main(mcp_dir):
print 'Using mcp dir: %s' % mcp_dir
print 'Using base dir: %s' % base_dir

print("Refreshing dependencies...")
download_deps( mcp_dir )
download_deps( mcp_dir, False )

sys.path.append(mcp_dir)
os.chdir(mcp_dir)
Expand Down Expand Up @@ -144,4 +195,4 @@ def main(mcp_dir):
elif os.path.isfile(os.path.join('..', 'runtime', 'commands.py')):
main(os.path.abspath('..'))
else:
main(os.path.abspath('mcp908'))
main(os.path.abspath(mcp_version))
5 changes: 3 additions & 2 deletions copybuildanddiffchangestopub.bat
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
SET MINECRIFT_SRCROOT=C:\minecrift-src
SET MINECRIFTPUB_SRCROOT=C:\minecrift-public
SET MCP_VERSION=mcp910-pre1

rmdir /S /Q %MINECRIFTPUB_SRCROOT%\mcp908\src\minecraft
xcopy /E %MINECRIFT_SRCROOT% %MINECRIFTPUB_SRCROOT%\mcp908\src\minecraft\
rmdir /S /Q %MINECRIFTPUB_SRCROOT%\%MCP_VERSION%\src\minecraft
xcopy /E %MINECRIFT_SRCROOT% %MINECRIFTPUB_SRCROOT%\%MCP_VERSION%\src\minecraft\
cd %MINECRIFTPUB_SRCROOT%
call build.bat
call getchanges.bat
4 changes: 3 additions & 1 deletion create_install.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python
from build import create_install
create_install("mcp908")
from install import mcp_version

create_install(mcp_version)
1 change: 0 additions & 1 deletion getchanges.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
@echo off
REM.\mcp\runtime\bin\python\python_mcp getchanges.py
python getchanges.py
10 changes: 9 additions & 1 deletion getchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import shutil, glob, fnmatch
import subprocess, logging, shlex, re
from optparse import OptionParser
from minecriftversion import mcp_version, minecrift_version_num, minecrift_build
from build import replacelineinfile

base_dir = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -14,6 +16,7 @@ def cmdsplit(args):

def create_patch( target_dir, src_file, mod_file, label, patch_file ):

print "Checking patch status for %s..." % src_file
if os.name == 'nt':
diff = os.path.abspath(os.path.join(base_dir, 'bin', 'diff.exe'))
else:
Expand Down Expand Up @@ -62,6 +65,11 @@ def main(mcp_dir):
if mod_file[-4:]!="java":
continue

if file_ == "Minecraft.java":
# Update Minecrift version
print "Updating Minecraft.java Minecrift version: [Minecrift %s %s] %s" % ( minecrift_version_num, minecrift_build, org_file )
replacelineinfile( mod_file, "public final String minecriftVerString", " public final String minecriftVerString = \"Minecrift %s %s\";\n" % (minecrift_version_num, minecrift_build) );

if os.path.exists(org_file):
patch_file = os.path.join(patch_dir,file_+".patch")
label = pkg.replace("\\","/") + "/" + file_ #patch label always has "/"
Expand All @@ -85,4 +93,4 @@ def main(mcp_dir):
elif os.path.isfile(os.path.join('..', 'runtime', 'commands.py')):
main(os.path.abspath('..'))
else:
main(os.path.abspath('mcp908'))
main(os.path.abspath(mcp_version))
4 changes: 1 addition & 3 deletions install.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@echo off
python install.py %*

REM.\mcp\runtime\bin\python\python_mcp install.py
python install.py
pause
Loading

0 comments on commit 0f69a3b

Please sign in to comment.