-
Notifications
You must be signed in to change notification settings - Fork 0
/
CCMMController.py
executable file
·144 lines (108 loc) · 4.77 KB
/
CCMMController.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
#
# CCMMController.py
# MCCMM
#
# Created by Frigid on 1/15/10.
# Copyright (c) 2010 __MyCompanyName__. All rights reserved.
#
import os
from objc import IBAction
from Foundation import *
from Cocoa import *
import modmover
from ModScanner import ModScanner
import CCDir as ccDir
class CCMMController(NSObject):
arrayMods = objc.IBOutlet('arrayMods')
tableView = objc.IBOutlet('tableView')
runBtn = objc.IBOutlet('runBtn')
CCDir = objc.ivar('CCDir')
CCApp = objc.ivar('CCApp')
CCPath = objc.ivar('CCPath')
mods = objc.ivar('mods')
def setRunBtnImage(self):
self.runBtn.setLabel_(u"Run " + self.CCApp.split("/")[-1].split(".")[-2])
print "Getting CC Icon..."
print str(self.CCPath) + "ccosx.icns"
if os.path.exists(str(self.CCPath) + "ccosx.icns"):
print "Icon Found!"
self.runBtn.setImage_(NSImage.alloc().initByReferencingFile_(str(self.CCPath) + "ccosx.icns"))
def awakeFromNib(self):
self.CCDir = ccDir.CCDir.alloc().init()
self.CCApp = self.CCDir.getCCApp()
if self.CCApp == None:
NSApp.terminate_(None)
self.CCPath = self.CCApp + "/Contents/Resources/"
self.setRunBtnImage()
self.mods = NSMutableArray.alloc().init()
self.scanMods_(None)
nameDescriptior = NSSortDescriptor.alloc().initWithKey_ascending_(u"modName", True)
self.tableView.setSortDescriptors_([nameDescriptior,])
@IBAction
def runCC_(self, sender):
os.system("open \""+self.CCApp+"\"")
@IBAction
def scanMods_(self, sender):
modScanner = ModScanner.alloc().init()
modScanner.setModPath_(self.CCPath)
self.mods = NSMutableArray.alloc().initWithArray_(modScanner.getModArray())
self.mods.sortUsingDescriptors_(self.tableView.sortDescriptors())
self.tableView.reloadData()
@IBAction
def getCCDir_(self, sender):
self.CCApp = self.CCDir.getNewApp_(self.CCApp)
self.CCPath = self.CCApp + "/Contents/Resources/"
self.scanMods_(None)
self.setRunBtnImage()
@IBAction
def checkBtn_(self, sender):
modfolder = str(self.mods[sender.selectedRow()]["modFolder"])
modname = str(self.mods[sender.selectedRow()]["modName"])
enabled = self.mods[sender.selectedRow()]["modIsEnabled"]
if enabled == True:
print "Disabling " + modfolder
modmover.disableMod(self.CCPath, modfolder)
else:
print "Enabling " + modfolder
modmover.enableMod(self.CCPath, modfolder)
self.scanMods_(None)
@IBAction
def toggleAll_(self, sender):
if sender.selectedSegment() == 0: #Enable All
for mod in self.mods:
modfolder = str(mod["modFolder"])
modname = str(mod["modName"])
enabled = mod["modIsEnabled"]
if enabled == False:
print "Enabling " + modfolder
modmover.enableMod(self.CCPath, modfolder)
else: #Disable All
for mod in self.mods:
modfolder = str(mod["modFolder"])
modname = str(mod["modName"])
enabled = mod["modIsEnabled"]
if enabled == True:
print "Disabling " + modfolder
modmover.disableMod(self.CCPath, modfolder)
self.scanMods_(None)
def tableView_objectValueForTableColumn_row_(self, aTableView, aTableColumn, rowIndex):
if rowIndex >= 0 and rowIndex < self.mods.count():
theRecord = self.mods.objectAtIndex_(rowIndex)
theValue = theRecord.objectForKey_(aTableColumn.identifier())
return theValue
else:
NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
u"Number of entries are mismatched. Contact app creator and report bug.",
None,
None,
None,
u"rowIndex is less than or equal to 0, or smaller than the number of mods.")
def numberOfRowsInTableView_(self, aTableView):
if not self.mods:
self.mods = NSArray.alloc().init()
return self.mods.count()
#This delegate function is for sorting the columns when the respective header is clicked.
def tableView_sortDescriptorsDidChange_(self, aTableView, oldDescriptors):
print aTableView.sortDescriptors()
self.mods.sortUsingDescriptors_(aTableView.sortDescriptors())
aTableView.reloadData()