Skip to content

Commit

Permalink
Release - 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
simon50keda committed Mar 2, 2017
1 parent 532e992 commit f5a846d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 12 deletions.
2 changes: 1 addition & 1 deletion addon/io_scs_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"name": "SCS Tools",
"description": "Setup models, Import-Export SCS data format",
"author": "Simon Lusenc (50keda), Milos Zajic (4museman)",
"version": (1, 6, "780f5be"),
"version": (1, 7, "df20e2d"),
"blender": (2, 78, 0),
"location": "File > Import-Export",
"wiki_url": "http://modding.scssoft.com/wiki/Documentation/Tools/SCS_Blender_Tools",
Expand Down
4 changes: 2 additions & 2 deletions addon/io_scs_tools/internals/open_gl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def _draw_3dview_report(region):
:param region: region of 3D viewport
:type region: bpy.types.Region
"""
pos = region.height - 65
pos = region.height - 62

if _Show3DViewReportOperator.has_lines():

Expand All @@ -441,7 +441,7 @@ def _draw_3dview_report(region):
glDisable(GL_TEXTURE_2D)

# draw version string
blf.size(0, 11, 72)
blf.size(0, 10, 72)
glColor3f(.952, .635, .062)
blf.position(0, 20, pos, 0)
blf.draw(0, _info_utils.get_combined_ver_str(only_version_numbers=True))
Expand Down
60 changes: 51 additions & 9 deletions addon/io_scs_tools/operators/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import os
import subprocess
import shutil
from hashlib import sha1
from sys import platform
from bpy.props import StringProperty, CollectionProperty, EnumProperty, IntProperty, BoolProperty
from io_scs_tools.consts import ConvHlpr as _CONV_HLPR_consts
Expand Down Expand Up @@ -1021,8 +1022,16 @@ def execute(self, context):
self.report({'ERROR'}, "Conversion tools path is incorrect! Please fix it first.")
return {'CANCELLED'}

if not os.path.isdir(_get_scs_globals().scs_project_path):
self.report({'ERROR'}, "SCS Project Base Path doesn't exists! Aborting Conversion!")
return {'CANCELLED'}

link_hash = "linked_bt_" + sha1(str.encode(_get_scs_globals().scs_project_path)).hexdigest()
linked_path = os.path.join(main_path, link_hash)
_path_utils.ensure_symlink(_get_scs_globals().scs_project_path, linked_path)

with open(extra_mount_path, mode="w") as f:
f.write(os.path.realpath(_get_scs_globals().scs_project_path))
f.write(link_hash)

return ConversionHelper.RunConversion.execute(self, context)

Expand Down Expand Up @@ -1059,11 +1068,24 @@ def execute(self, context):
self.report({'WARNING'}, "None existing custom paths detected, they were ignored!")
continue

f.write(path)
link_hash = "linked_bt_" + sha1(str.encode(path)).hexdigest()
linked_path = os.path.join(main_path, link_hash)
_path_utils.ensure_symlink(path, linked_path)

f.write(link_hash)
f.write("\r\n")

if self.include_current_project:
f.write(os.path.realpath(_get_scs_globals().scs_project_path))

if os.path.isdir(_get_scs_globals().scs_project_path):

link_hash = "linked_bt_" + sha1(str.encode(_get_scs_globals().scs_project_path)).hexdigest()
linked_path = os.path.join(main_path, link_hash)
_path_utils.ensure_symlink(_get_scs_globals().scs_project_path, linked_path)
f.write(link_hash)

else:
self.report({'WARNING'}, "None existing SCS Project Base Path detected, ignoring it!")

return ConversionHelper.RunConversion.execute(self, context)

Expand Down Expand Up @@ -1235,7 +1257,13 @@ def execute(self, context):
# do copy or zipping
if scs_globals.conv_hlpr_mod_compression == _CONV_HLPR_consts.NoZip:

shutil.copytree(rsrc_path, mod_filepath_as_dir)
for converted_dir in os.listdir(rsrc_path): # use old conversion tools behaviour and pack everything that is in rsrc

curr_dir = os.path.join(os.path.join(rsrc_path, converted_dir), "@cache")
if not os.path.isdir(curr_dir):
continue

shutil.copytree(curr_dir, mod_filepath_as_dir)

self.report({'INFO'}, "Packing done, mod copied to: '%s'" % mod_filepath_as_dir)

Expand All @@ -1245,13 +1273,27 @@ def execute(self, context):

with ZipFile(mod_filepath, 'w') as myzip:

for root, dirs, files in os.walk(rsrc_path):
for converted_dir in os.listdir(rsrc_path): # use old conversion tools behaviour and pack everything that is in rsrc

curr_dir = os.path.join(os.path.join(rsrc_path, converted_dir), "@cache")
if not os.path.isdir(curr_dir):
continue

for root, dirs, files in os.walk(curr_dir):

for file in files:

abs_file = os.path.join(root, file)
# Extract archive path+name, do conversion to proper slashes
# as zipfile namelist is returning only normal slashes even on windows and
# as last remove leading slash as zipfile namelist again doesn't have it.
archive_file = abs_file.replace(curr_dir, "").replace("\\", "/").lstrip("/")

for file in files:
if archive_file in myzip.namelist():
lprint("D Archive name %r already exists, ignoring it!" % archive_file)
continue

abs_file = os.path.join(root, file)
archive_file = abs_file.replace(rsrc_path, "")
myzip.write(abs_file, archive_file, compress_type=int(scs_globals.conv_hlpr_mod_compression))
myzip.write(abs_file, archive_file, compress_type=int(scs_globals.conv_hlpr_mod_compression))

self.report({'INFO'}, "Packing done, mod packed to: '%s'" % mod_filepath)

Expand Down
21 changes: 21 additions & 0 deletions addon/io_scs_tools/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import bpy
import os
import subprocess
from sys import platform
from io_scs_tools.utils.printout import lprint
from io_scs_tools.utils import get_scs_globals as _get_scs_globals

Expand Down Expand Up @@ -725,3 +727,22 @@ def readable_norm(path):
norm_path = norm_path.replace("\\", "/")

return norm_path


def ensure_symlink(src, dest):
"""Ensures symbolic link from source to destination. On Windows junction links are used
to avoid problems with link creation rights.
:param src: directory or file path from which should be taken as source for creation of symbolic link
:type src: str
:param dest: directory or file path where symbolic link should be written
:type dest: str
"""

if os.path.isdir(dest):
os.remove(dest) # use os.remove instead os.unlink, as we can't remove mklink junction with os.unlink.

if platform == "win32":
subprocess.check_call(["mklink", "/J", dest, src], shell=True)
else:
os.symlink(src, dest)

0 comments on commit f5a846d

Please sign in to comment.