forked from DefectiveStudios/UniMerge-Docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge-unity.vbs
83 lines (72 loc) · 3.55 KB
/
merge-unity.vbs
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
'Matt Schoen
'5-29-2013
'
'In the absence of a legitimate license (that I know of) that fits my needs, here goes: This software is the
'copyrighted material of its author, Matt Schoen, and his comapny Defective Studios. It is available for sale on
'the Unity Asset store and is subject to their restrictions and limitations, as well as the following: You shall not
'reproduce or re-distribute this software with the express written (e-mail is fine) permission of the author. If
'permission is granted, the code (this file and related files) must bear this license in its entirety. Anyone who
'purchases the script is welcome to modify end re-use the code at their personal risk and under the condition that
'it not be included in any disribution builds. The software is provided as-is without warranty and the author bears
'no responsiblity for damages or losses caused by the software. Enjoy it, it's yours, but just don't try to profit
'from it, OK?
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'unity.exe'")
dim objArgs,num,sMyDoc,sTheirDoc,ProjectBase
Set objArgs = WScript.Arguments
num = objArgs.Count
if num < 2 then
MsgBox "Usage: [CScript | WScript] merge-unity.vbs %mine %theirs", vbExclamation, "Invalid arguments"
WScript.Quit 1
end if
sMyDoc=objArgs(0)
sTheirDoc=objArgs(1)
Set FSObj = CreateObject("Scripting.FileSystemObject")
'ProjectBase = "D:\Documents\UniMerge\Project" 'if automatic pathfinding fails, use this line instead
ProjectBase = FSObj.GetAbsolutePathName(".") 'automatic pathfinding wil only work if script called from project folder
If Not FSObj.FolderExists(ProjectBase & "\Assets") Then
WScript.Echo("Path " & ProjectBase & "\Assets not found, try specifying an absolute project path")
End If
'If my doc is not in project path, copy to project
If InStr(sMyDoc, ProjectBase) = 0 Then
Set FSObj = CreateObject("Scripting.FileSystemObject")
sourceParts = Split(sMyDoc, "\")
destinationFile = ProjectBase & "\Assets\" & "MINE-" & sourceParts(UBound(sourceParts))
If FSObj.FileExists(sMyDoc) Then
If FSObj.FileExists(destinationFile) Then
'WScript.Echo("Cannot copy " + sMyDoc + " to " + destinationFile + " because the destination file exists")
Else
FSObj.MoveFile sMyDoc, destinationFile
End If
sMyDoc = destinationFile
End If
End If
'If their doc is not in project path, copy to project
If InStr(sTheirDoc, ProjectBase) = 0 Then
Set FSObj = CreateObject("Scripting.FileSystemObject")
sourceParts = Split(sTheirDoc, "\")
destinationFile = ProjectBase & "\Assets\" & "THEIRS-" & sourceParts(UBound(sourceParts))
If FSObj.FileExists(sTheirDoc) Then
If FSObj.FileExists(destinationFile) Then
'WScript.Echo("Cannot copy " + sTheirDoc + " to " + destinationFile + " because the destination file exists")
Else
FSObj.MoveFile sTheirDoc, destinationFile
End If
sTheirDoc = destinationFile
End If
End If
Dim objShell
Set objShell = WScript.CreateObject ("WScript.shell")
If colProcesses.Count > 0 Then
Set FSObj = CreateObject("Scripting.FileSystemObject")
Set FileObj = FSObj.CreateTextFile(ProjectBase + "\Assets\merges.txt")
FileObj.WriteLine(sMyDoc)
FileObj.WriteLine(sTheirDoc)
objShell.AppActivate("Unity")
Else
objShell.Run """C:\Program Files\Unity5\Editor\Unity.exe"" -executeMethod SceneMerge.CLIIn """ + sMyDoc + """ """ + sTheirDoc
Set objShell = Nothing
End If