-
Notifications
You must be signed in to change notification settings - Fork 79
/
_mergeability.py
195 lines (187 loc) · 8.07 KB
/
_mergeability.py
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# -*- coding: utf-8 -*-
#
# GPL License and Copyright Notice ============================================
# This file is part of Wrye Bash.
#
# Wrye Bash is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# Wrye Bash 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 Wrye Bash; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Wrye Bash copyright (C) 2005-2009 Wrye, 2010-2015 Wrye Bash Team
# https://github.com/wrye-bash
#
# =============================================================================
"""Tmp module to get mergeability stuff out of bosh.__init__.py."""
from .. import bass, bush
from ..bolt import GPath
from ..brec import ModError
from ..cint import ObCollection
from ..load_order import cached_is_active
from ..parsers import ModFile, LoadFactory
def _is_mergeable_no_load(modInfo, verbose):
reasons = []
if modInfo.isEsm():
if not verbose: return False
reasons.append(u'\n. '+_(u'Is esm.'))
#--Bashed Patch
if modInfo.header.author == u'BASHED PATCH':
if not verbose: return False
reasons.append(u'\n. '+_(u'Is Bashed Patch.'))
#--Bsa / voice?
if modInfo.isMod() and tuple(modInfo.hasResources()) != (False,False):
if not verbose: return False
hasBsa, hasVoices = modInfo.hasResources()
if hasBsa:
reasons.append(u'\n. '+_(u'Has BSA archive.'))
if hasVoices:
reasons.append(u'\n. '+_(u'Has associated voice directory (Sound\\Voice\\%s).') % modInfo.name.s)
#-- Check to make sure NoMerge tag not in tags - if in tags don't show up as mergeable.
tags = modInfo.getBashTags()
if u'NoMerge' in tags:
if not verbose: return False
reasons.append(u'\n. '+_(u"Has 'NoMerge' tag."))
if reasons: return reasons
return True
def pbash_mergeable_no_load(modInfo, verbose):
reasons = _is_mergeable_no_load(modInfo, verbose)
if isinstance(reasons, list):
reasons = u''.join(reasons)
elif not reasons:
return False # non verbose mode
else: # True
reasons = u''
#--Missing Strings Files?
if modInfo.isMissingStrings():
if not verbose: return False
from . import oblivionIni
reasons += u'\n. '+_(u'Missing String Translation Files (Strings\\%s_%s.STRINGS, etc).') % (
modInfo.name.sbody, oblivionIni.get_ini_language())
if reasons: return reasons
return True
def isPBashMergeable(modInfo, minfos, verbose=True):
"""Returns True or error message indicating whether specified mod is mergeable."""
reasons = pbash_mergeable_no_load(modInfo, verbose)
if isinstance(reasons, unicode):
pass
elif not reasons:
return False # non verbose mode
else: # True
reasons = u''
#--Load test
mergeTypes = set([recClass.classType for recClass in bush.game.mergeClasses])
modFile = ModFile(modInfo, LoadFactory(False, *mergeTypes))
try:
modFile.load(True,loadStrings=False)
except ModError as error:
if not verbose: return False
reasons += u'\n. %s.' % error
#--Skipped over types?
if modFile.topsSkipped:
if not verbose: return False
reasons += u'\n. '+_(u'Unsupported types: ')+u', '.join(sorted(modFile.topsSkipped))+u'.'
#--Empty mod
elif not modFile.tops:
if not verbose: return False
reasons += u'\n. '+ u'Empty mod.'
#--New record
lenMasters = len(modFile.tes4.masters)
newblocks = []
for type,block in modFile.tops.iteritems():
for record in block.getActiveRecords():
if record.fid >> 24 >= lenMasters:
if record.flags1.deleted: continue #if new records exist but are deleted just skip em.
if not verbose: return False
newblocks.append(type)
break
if newblocks: reasons += u'\n. '+_(u'New record(s) in block(s): ')+u', '.join(sorted(newblocks))+u'.'
dependent = [name.s for name, info in minfos.iteritems()
if info.header.author != u'BASHED PATCH'
if modInfo.name in info.header.masters]
if dependent:
if not verbose: return False
reasons += u'\n. '+_(u'Is a master of mod(s): ')+u', '.join(sorted(dependent))+u'.'
if reasons: return reasons
return True
def cbash_mergeable_no_load(modInfo, verbose):
"""Check if mod is mergeable without taking into account the rest of mods"""
return _is_mergeable_no_load(modInfo, verbose)
def _modIsMergeableLoad(modInfo, minfos, verbose):
"""Check if mod is mergeable, loading it and taking into account the
rest of mods."""
allowMissingMasters = {u'Filter', u'IIM', u'InventOnly'}
tags = modInfo.getBashTags()
reasons = []
#--Load test
with ObCollection(ModsPath=bass.dirs['mods'].s) as Current:
#MinLoad, InLoadOrder, AddMasters, TrackNewTypes, SkipAllRecords
modFile = Current.addMod(modInfo.getPath().stail, Flags=0x00002129)
Current.load()
missingMasters = []
nonActiveMasters = []
masters = modFile.TES4.masters
for master in masters:
master = GPath(master)
if not tags & allowMissingMasters:
if master not in minfos:
if not verbose: return False
missingMasters.append(master.s)
elif not cached_is_active(master):
if not verbose: return False
nonActiveMasters.append(master.s)
#--masters not present in mod list?
if len(missingMasters):
if not verbose: return False
reasons.append(u'\n. '+_(u'Masters missing: ')+u'\n * %s' % (u'\n * '.join(sorted(missingMasters))))
if len(nonActiveMasters):
if not verbose: return False
reasons.append(u'\n. '+_(u'Masters not active: ')+u'\n * %s' % (u'\n * '.join(sorted(nonActiveMasters))))
#--Empty mod
if modFile.IsEmpty():
if not verbose: return False
reasons.append(u'\n. '+_(u'Empty mod.'))
#--New record
else:
if not tags & allowMissingMasters:
newblocks = modFile.GetNewRecordTypes()
if newblocks:
if not verbose: return False
reasons.append(u'\n. '+_(u'New record(s) in block(s): %s.') % u', '.join(sorted(newblocks)))
dependent = [name.s for name, info in minfos.iteritems()
if info.header.author != u'BASHED PATCH' and
modInfo.name in info.header.masters and name not in minfos.mergeable]
if dependent:
if not verbose: return False
reasons.append(u'\n. '+_(u'Is a master of non-mergeable mod(s): %s.') % u', '.join(sorted(dependent)))
if reasons: return reasons
return True
# noinspection PySimplifyBooleanCheck
def isCBashMergeable(modInfo, minfos, verbose=True):
"""Returns True or error message indicating whether specified mod is mergeable."""
if modInfo.name.s == u"Oscuro's_Oblivion_Overhaul.esp":
if verbose: return u'\n. ' + _(
u'Marked non-mergeable at request of mod author.')
return False
canmerge = cbash_mergeable_no_load(modInfo, verbose)
if verbose:
loadreasons = _modIsMergeableLoad(modInfo, minfos, verbose)
reasons = []
if canmerge != True:
reasons = canmerge
if loadreasons != True:
reasons.extend(loadreasons)
if reasons: return u''.join(reasons)
return True
else:
if canmerge == True:
return _modIsMergeableLoad(modInfo, minfos, verbose)
return False