aboutsummaryrefslogtreecommitdiff
path: root/Core/Scripts/System/ART_Updater.py
blob: 5cc4b6126133d0a4790ed616369288892d724e61 (plain) (blame)
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
from ThirdParty.Qt import QtGui, QtCore, QtWidgets
import maya.cmds as cmds
import os, json
import utils, math, traceback, urllib2, zipfile
import shutil, errno, stat, base64
import System.git_utils as git

#maya 2016< 2017> compatability
try:
    import shiboken as shiboken
except:
    import shiboken2 as shiboken



def getMainWindow():
    import maya.OpenMayaUI as mui
    pointer = mui.MQtUtil.mainWindow()
    #pyside QMainWindow takes in a QWidget rather than QObject
    return shiboken.wrapInstance(long(pointer), QtWidgets.QWidget)



windowTitle = "ARTv2: Check For Updates"
windowObject = "pyArtUpdaterWin"



class ART_Updater(QtWidgets.QMainWindow):

    def __init__(self, parent = None):

        super(ART_Updater, self).__init__(parent)

        #get the directory path of the tools
        settings = QtCore.QSettings("Epic Games", "ARTv2")

        self.toolsPath = settings.value("toolsPath")
        self.scriptPath = settings.value("scriptPath")
        self.iconsPath = settings.value("iconPath")
        self.projPath = settings.value("projectPath")

        #get github credentials
        self.credentials = git.getGitCreds()
        if self.credentials == None:
            git.gitCredsUI(self)
            self.credentials = git.getGitCreds()



        #build the UI
        self.buildSettingsUi()



# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def buildSettingsUi(self):

        #fonts
        self.font = QtGui.QFont()
        self.font.setPointSize(10)
        self.font.setBold(False)

        self.fontSmall = QtGui.QFont()
        self.fontSmall .setPointSize(9)
        self.fontSmall .setBold(False)

        self.titleFont = QtGui.QFont()
        self.titleFont.setPointSize(40)
        self.titleFont.setBold(True)


        #images
        frameBackground =  os.path.normcase(os.path.join(self.iconsPath, "System/field_background.png"))
        if frameBackground.partition("\\")[2] != "":
            frameBackground = frameBackground.replace("\\", "/")

        imageBkgrd =  os.path.normcase(os.path.join(self.iconsPath, "System/toolbar_background.png"))
        if imageBkgrd.partition("\\")[2] != "":
            imageBkgrd = imageBkgrd.replace("\\", "/")

        imageBtnBkrd =  os.path.normcase(os.path.join(self.iconsPath, "System/blue_field_background.png"))
        if imageBtnBkrd.partition("\\")[2] != "":
            imageBtnBkrd = imageBtnBkrd.replace("\\", "/")

        #load stylesheet
        styleSheetFile = utils.returnNicePath(self.toolsPath, "Core/Scripts/Interfaces/StyleSheets/mainScheme.qss")
        f = open(styleSheetFile, "r")
        self.style = f.read()
        f.close()


        self.setStyleSheet(self.style)

        #size policies
        mainSizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)

        #create the main widget
        self.mainWidget = QtWidgets.QWidget()
        self.mainWidget.setStyleSheet(self.style)
        self.mainWidget.setStyleSheet("background-color: rgb(0, 0, 0);, color: rgb(0,0,0);")
        self.setCentralWidget(self.mainWidget)

        #set qt object name
        self.setObjectName(windowObject)
        self.setWindowTitle(windowTitle)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        #create the mainLayout for the rig creator UI
        self.layout = QtWidgets.QVBoxLayout(self.mainWidget)

        self.resize(600, 300)
        self.setSizePolicy(mainSizePolicy)
        self.setMinimumSize(QtCore.QSize( 600, 300 ))
        self.setMaximumSize(QtCore.QSize( 600, 300 ))


        #create the QFrame
        self.frame = QtWidgets.QFrame()
        self.layout.addWidget(self.frame)
        self.widgetLayout = QtWidgets.QVBoxLayout(self.frame)

        #info page styling
        self.frame.setStyleSheet("background-image: url(" + imageBkgrd + ");")


        #detailed information
        self.infoText = QtWidgets.QTextEdit()
        self.infoText.acceptRichText()
        self.infoText.setStyleSheet("background-color: rgb(120,120,120); background-image: url(" + frameBackground + ");")
        self.widgetLayout.addWidget(self.infoText)
        self.infoText.setMinimumSize(QtCore.QSize(550,170))
        self.infoText.setMaximumSize(QtCore.QSize(550,170))
        self.infoText.setReadOnly(True)
        self.infoText.setAutoFormatting(QtWidgets.QTextEdit.AutoBulletList)
        self.infoText.setLineWrapMode(QtWidgets.QTextEdit.WidgetWidth)


        #progress bar
        self.progressBar = QtWidgets.QProgressBar()
        self.progressBar.setStyleSheet(self.style)
        self.progressBar.setMinimumSize(QtCore.QSize(550, 25))
        self.progressBar.setMaximumSize(QtCore.QSize(550, 25))
        self.widgetLayout.addWidget(self.progressBar)

        #button bar
        self.buttonLayout = QtWidgets.QHBoxLayout()
        self.widgetLayout.addLayout(self.buttonLayout)

        self.cancelButton = QtWidgets.QPushButton("Close")
        self.buttonLayout.addWidget(self.cancelButton)
        self.cancelButton.setStyleSheet(self.style)
        self.cancelButton.setObjectName("blueButton")
        self.cancelButton.clicked.connect(self.cancel)

        self.updateButton = QtWidgets.QPushButton("Update")
        self.buttonLayout.addWidget(self.updateButton)
        self.updateButton.setStyleSheet(self.style)
        self.updateButton.setObjectName("blueButton")
        self.updateButton.clicked.connect(self.downloadUpdates)

        if self.credentials != None:
            self.getInfo()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def getInfo(self):

        #need to eventually swap this with the real file
        request = urllib2.Request("https://raw.githubusercontent.com/epicernst/Test/master/ARTv2_VersionInfo.json")
        base64String = base64.encodestring('%s:%s' % (self.credentials[0], self.credentials[1])).replace('\n', '')
        request.add_header("Authorization", "Basic %s" % base64String)
        try:
            result = urllib2.urlopen(request)
        except Exception, e:
            self.infoText.setTextColor(QtGui.QColor(249,241,12))
            self.infoText.append(str(e))
            self.infoText.append("Your Github login credentials may be invalid or you do not have access to this repo.\n\n")
            self.infoText.setTextColor(QtGui.QColor(255,255,255))

            settings = QtCore.QSettings("Epic Games", "ARTv2")
            settings.remove("gitUser")
            settings.remove("gitPass")

            return


        content = json.loads(result.read())
        versions = content.get("versions")

        newFeatures = []
        majorFixes = []
        minorFixes = []

        for version in versions:
            data = versions.get(version)
            for key in data:
                if key == "New":
                    info = data.get(key)
                    for each in info:
                        newFeatures.append(each)

                if key == "Critical":
                    info = data.get(key)
                    for each in info:
                        majorFixes.append(each)

                if key == "Minor":
                    info = data.get(key)
                    for each in info:
                        minorFixes.append(each)


        #Compare local version to latest
        latestVersion = content.get("latest version")
        localVersion = self.checkLocalVersion()

        if float(latestVersion) > float(localVersion):
            self.infoText.append("You are not up to date!\n")
            self.infoText.append("Latest Version:   " + str(content.get("latest version")))
            self.infoText.append("Local Version:    " + str(localVersion))

            self.infoText.append("\n")


            #release notes
            self.infoText.setFont(self.titleFont)
            self.infoText.setTextColor(QtGui.QColor(48,255,0))
            self.infoText.setAlignment(QtCore.Qt.AlignCenter)
            self.infoText.append("|| NEW FEATURES ||")

            self.infoText.setFont(self.fontSmall)
            self.infoText.setAlignment(QtCore.Qt.AlignLeft)
            self.infoText.setTextColor(QtGui.QColor(255,255,255))
            for feature in newFeatures:
                self.infoText.append("        *" + str(feature))

            self.infoText.append("\n")
            self.infoText.setFont(self.titleFont)
            self.infoText.setTextColor(QtGui.QColor(249,168,12))
            self.infoText.setAlignment(QtCore.Qt.AlignCenter)
            self.infoText.append("|| MAJOR FIXES ||")

            self.infoText.setFont(self.fontSmall)
            self.infoText.setAlignment(QtCore.Qt.AlignLeft)
            self.infoText.setTextColor(QtGui.QColor(255,255,255))
            for fix in majorFixes:
                self.infoText.append("        *" + str(fix))

            self.infoText.append("\n")
            self.infoText.setFont(self.titleFont)
            self.infoText.setTextColor(QtGui.QColor(249,241,12))
            self.infoText.setAlignment(QtCore.Qt.AlignCenter)
            self.infoText.append("|| MINOR FIXES ||")

            self.infoText.setFont(self.fontSmall)
            self.infoText.setAlignment(QtCore.Qt.AlignLeft)
            self.infoText.setTextColor(QtGui.QColor(255,255,255))
            for each in minorFixes:
                self.infoText.append("        *" + str(each))

            self.infoText.moveCursor(QtGui.QTextCursor.Start)

        else:
            self.infoText.append("You are up-to-date!")


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def checkLocalVersion(self):

        mayaModDir = os.environ["home"] + "/maya/modules/"
        if cmds.about(os = True) == "mac":
            mayaModDir = os.environ["home"] + "/Library/Preferences/Autodesk/maya/modules/"

        modName = "ARTv2.mod"
        modFile = mayaModDir + modName

        modFileObj = file(modFile, mode='r')
        lines = modFileObj.readlines()
        modFileObj.close()

        localVersion = float(lines[0].split(" ")[2])

        return localVersion


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def checkLatestVersion(self):

        info = git.getGitCreds()
        if info != None:
            user = info[0]
            password = info[1]

            #need to eventually swap this with the real file
            request = urllib2.Request("https://raw.githubusercontent.com/epicernst/Test/master/ARTv2_VersionInfo.json")
            base64String = base64.encodestring('%s:%s' % (user, password)).replace('\n', '')
            request.add_header("Authorization", "Basic %s" % base64String)
            result = urllib2.urlopen(request)
            content = json.loads(result.read())

            latestVersion = content.get("latest version")
            return latestVersion

        else:
            self.invalidCreds()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def updateLocalVersion(self):

        info = git.getGitCreds()
        if info != None:
            mayaModDir = cmds.internalVar(uad = True)
            mayaModDir = os.path.join(mayaModDir, "modules")
            mayaModDir = utils.returnFriendlyPath(os.path.join(mayaModDir, "ARTv2.mod"))

            if os.path.exists(mayaModDir):
                f = open(mayaModDir, 'r')
                line = f.readline()
                f.close()

                if line.find("+ ARTv2 ") != -1:
                    version = line.partition("+ ARTv2 ")[2].partition(" ")[0]
                    latest = self.checkLatestVersion()
                    newline = line.replace(str(version), str(latest))

                    f = open(mayaModDir, 'w')
                    f.write(newline)
                    f.close()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def findReadOnlyFiles(self, fullPath, listOfFiles):

        #list file contents
        contents = os.listdir(fullPath)
        for each in contents:
            if os.path.isfile(os.path.join(fullPath, each)):
                fileAttr = os.stat(os.path.join(fullPath, each)).st_mode
                if not fileAttr & stat.S_IWRITE:
                    try:
                        os.chmod(os.path.join(fullPath, each), stat.S_IWRITE)
                    except Exception, e:
                        listOfFiles.append([each, e])
            if os.path.isdir(os.path.join(fullPath, each)):
                self.findReadOnlyFiles(os.path.join(fullPath, each), listOfFiles)

        return listOfFiles

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def downloadUpdates(self):

        info = git.getGitCreds()
        if info != None:
            user = info[0]
            password = info[1]

        else:
            self.invalidCreds()
            return

        base64String = base64.encodestring('%s:%s' % (user, password)).replace('\n', '')
        opener = urllib2.build_opener()
        opener.addheaders = [("Authorization", "Basic %s" % base64String)]
        response = opener.open("https://github.com/epicernst/Test/archive/master.zip")

        zipContent = response.read()

        filename = os.path.basename("https://github.com/epicernst/Test/blob/master/master.zip")
        path = os.environ["home"]
        filePath = os.path.join(path, filename)

        with open(filePath, 'w') as f:
            f.write(zipContent)


        masterDir = os.path.dirname(filePath)
        mayaToolsZip = masterDir


        with zipfile.ZipFile(filePath, 'r') as zfile:
            for name in zfile.namelist():
                if name.find(".zip") != -1:
                    mayaToolsZip = os.path.join(mayaToolsZip, name)
            zfile.extractall(masterDir)



        baseToolsDir = os.path.dirname(self.toolsPath)
        wholeCopy = False

        fileIssues = []
        with zipfile.ZipFile(mayaToolsZip) as zf:
            removeDirs = ["MayaTools/Core/Scripts/", "MayaTools/Core/Icons/", "MayaTools/Core/JointMover/", "MayaTools/plug-ins/"]

            #set progress bar range
            self.progressBar.setMaximum(len(removeDirs) + 1)
            self.progressBar.setValue(0)

            for dir in removeDirs:
                fullPath = os.path.normpath(os.path.join(baseToolsDir, dir))

                #list file contents
                readOnlyFiles = self.findReadOnlyFiles(fullPath, fileIssues)

                #if readOnlyFiles is empty
                if len(readOnlyFiles) == 0:

                    #make a back-up of local versions
                    self.infoText.setTextColor(QtGui.QColor(0,0,0))
                    self.infoText.append("\n########################################################\n")
                    self.infoText.setTextColor(QtGui.QColor(255,255,255))
                    self.infoText.append("Creating Backup of current version.. " + str(dir))
                    self.infoText.moveCursor(QtGui.QTextCursor.End)

                    versionNumber = self.checkLocalVersion()
                    backupDir = os.path.join(os.path.dirname(self.toolsPath), "ARTv2/Backups")
                    backupDir = os.path.normpath(os.path.join(backupDir, str(versionNumber)))
                    printDir = backupDir
                    backupDir = utils.returnFriendlyPath(backupDir)
                    if not os.path.exists(backupDir):
                        os.makedirs(backupDir)

                    fullPath = utils.returnFriendlyPath(fullPath)

                    try:
                        shutil.move(fullPath, backupDir)
                        self.infoText.append("    Backups created in " + str(printDir))
                        self.infoText.moveCursor(QtGui.QTextCursor.End)
                    except Exception, e:
                        self.infoText.setTextColor(QtGui.QColor(249,168,12))
                        self.infoText.append(str(e))
                        self.infoText.setTextColor(QtGui.QColor(255,255,255))
                        wholeCopy = True

                    #extract zip file directory to original location
                    if wholeCopy == False:
                        for name in zf.namelist():
                            for each in removeDirs:
                                if name.find(each)!= -1:
                                    #extract directly to the base location
                                    try:
                                        zf.extract(name, baseToolsDir)

                                    except Exception, e:
                                        self.infoText.setTextColor(QtGui.QColor(249,168,12))
                                        self.infoText.append(str(e))
                                        self.infoText.setTextColor(QtGui.QColor(255,255,255))
                                        wholeCopy = True
                        self.infoText.append("    Extracted updated files to " + str(dir))
                        self.infoText.moveCursor(QtGui.QTextCursor.End)

                    #report on operations
                    value = self.progressBar.value()
                    self.progressBar.setValue(value + 1)




                #if readOnlyFiles is not empty
                else:
                    wholeCopy = True
                    if len(readOnlyFiles) > 0:
                        self.infoText.append("The following files were marked as read-only and could not be updated:")
                        for file in readOnlyFiles:
                            self.infoText.append("    " + str(file))
                            self.infoText.moveCursor(QtGui.QTextCursor.End)

            if wholeCopy:
                #report issues in UI
                self.infoText.setTextColor(QtGui.QColor(249,168,12))
                self.infoText.append("Could not apply updates automatically.")
                self.infoText.moveCursor(QtGui.QTextCursor.End)
                self.infoText.setTextColor(QtGui.QColor(255,255,255))


                #extract all to an Update folder
                version = self.checkLatestVersion()
                self.infoText.setTextColor(QtGui.QColor(255,255,255))
                updateDir = os.path.join(self.toolsPath, "Update_" + str(version))
                if not os.path.exists(updateDir):
                    os.makedirs(updateDir)

                self.infoText.append("Extracting updated files to:\n    " + str(updateDir))
                try:
                    zf.extractall(updateDir)
                except Exception, e:
                    self.infoText.setTextColor(QtGui.QColor(249,168,12))
                    self.infoText.append("Operation Failed")
                    self.infoText.append(str(e))
                    self.infoText.moveCursor(QtGui.QTextCursor.End)

                #report on operation
                self.infoText.append("Update Extracted. Since the automatic operation failed, you will need to manually integrate and apply the updates.")
                self.infoText.moveCursor(QtGui.QTextCursor.End)

            else:
                self.infoText.setTextColor(QtGui.QColor(48,255,0))
                self.infoText.append("\n\nUpdate Operation Completed!")
                self.infoText.append("You must restart Maya to have updates applied.")
                self.infoText.moveCursor(QtGui.QTextCursor.End)


        #delete zipFile
        try:
            os.remove(filePath)

            for each in os.listdir(os.path.dirname(mayaToolsZip)):
                path = os.path.dirname(mayaToolsZip)
                path = os.path.join(path, each)
                os.remove(path)

            os.chmod(os.path.dirname(mayaToolsZip), stat.S_IWRITE)
            shutil.rmtree(os.path.dirname(mayaToolsZip))

        except Exception, e:
            self.infoText.append("Unable to clean up temporary files..")
            self.infoText.append(str(e))

        value = self.progressBar.value()
        self.progressBar.setValue(value + 1)

        #update .mod file with latest version #
        self.updateLocalVersion()







# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def cancel(self):
        self.close()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def invalidCreds(self):

        self.infoText.setTextColor(QtGui.QColor(249,241,12))
        self.infoText.append("You have either not setup your Github credentials under Settings, or your github account is not linked with your Epic Games account.")
        self.infoText.append("For more information on linking your github and Epic Games accounts, see:\n")
        self.infoText.append("https://www.unrealengine.com/ue4-on-github")
        self.infoText.setTextColor(QtGui.QColor(255,255,255))

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def run():

    if cmds.window("pyArtUpdaterWin", exists = True):
        cmds.deleteUI("pyArtUpdaterWin", wnd = True)

    gui = ART_Updater(getMainWindow())
    gui.show()