mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-08-01 01:15:59 -04:00
who isn't sick of converting the freaking scripts? this negates the need
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package script.developer;
|
||||
|
||||
import script.*;
|
||||
import script.base_class.*;
|
||||
import script.combat_engine.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import script.base_script;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.FileWriter;
|
||||
|
||||
public class file_access extends script.base_script
|
||||
{
|
||||
public file_access()
|
||||
{
|
||||
}
|
||||
public static String readTextFile(String fileName) throws InterruptedException
|
||||
{
|
||||
String result = null;
|
||||
File f = new File(fileName);
|
||||
if (f.exists())
|
||||
{
|
||||
long len = f.length();
|
||||
if (len > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileInputStream inputStream = new FileInputStream(f);
|
||||
byte[] buf = new byte[(int)len];
|
||||
inputStream.read(buf);
|
||||
result = new String(buf);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
sendSystemMessageTestingOnly(self, "An exception occurred while trying to read " + fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static boolean isWritable(String fileName) throws InterruptedException
|
||||
{
|
||||
boolean result = false;
|
||||
File f = new File(fileName);
|
||||
if (f.exists())
|
||||
{
|
||||
if (f.canWrite())
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static boolean writeTextFile(String fileName, String fileContents) throws InterruptedException
|
||||
{
|
||||
boolean result = false;
|
||||
File f = new File(fileName);
|
||||
if (!f.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
f.createNewFile();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (f.canWrite())
|
||||
{
|
||||
f.delete();
|
||||
try
|
||||
{
|
||||
if (f.createNewFile())
|
||||
{
|
||||
FileWriter writer = new FileWriter(f);
|
||||
writer.write(fileContents);
|
||||
writer.close();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
sendSystemMessageTestingOnly(self, "failed to write " + fileName + " : " + e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
include java.io.File;
|
||||
include java.io.FileInputStream;
|
||||
include java.io.InputStream;
|
||||
include java.io.FileWriter;
|
||||
|
||||
String readTextFile(String fileName)
|
||||
{
|
||||
String result = null;
|
||||
File f = new File(fileName);
|
||||
if(f.exists())
|
||||
{
|
||||
long len = f.length();
|
||||
if(len > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileInputStream inputStream = new FileInputStream(f);
|
||||
byte[] buf = new byte[(int)len];
|
||||
inputStream.read(buf);
|
||||
result = new String(buf);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
sendSystemMessageTestingOnly(self, "An exception occurred while trying to read " + fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean isWritable(String fileName)
|
||||
{
|
||||
boolean result = false;
|
||||
File f = new File(fileName);
|
||||
if(f.exists())
|
||||
{
|
||||
if(f.canWrite())
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean writeTextFile(String fileName, String fileContents)
|
||||
{
|
||||
boolean result = false;
|
||||
File f = new File(fileName);
|
||||
|
||||
if(!f.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
f.createNewFile();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(f.canWrite())
|
||||
{
|
||||
f.delete();
|
||||
try
|
||||
{
|
||||
if(f.createNewFile())
|
||||
{
|
||||
FileWriter writer = new FileWriter(f);
|
||||
writer.write(fileContents);
|
||||
writer.close();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
sendSystemMessageTestingOnly(self, "failed to write " + fileName + " : " + e);
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
package script.developer;
|
||||
|
||||
import script.*;
|
||||
import script.base_class.*;
|
||||
import script.combat_engine.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import script.base_script;
|
||||
|
||||
import java.lang.Runtime;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.IOException;
|
||||
import script.library.chat;
|
||||
import script.developer.file_access;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.BufferedReader;
|
||||
|
||||
public class perforce extends script.base_script
|
||||
{
|
||||
public perforce()
|
||||
{
|
||||
}
|
||||
public static String getIdOptions() throws InterruptedException
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
if (!isGod(self))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String userId = getStringObjVar(self, "P4USER");
|
||||
String password = getStringObjVar(self, "P4PASSWD");
|
||||
return "-P " + password + " -u " + userId;
|
||||
}
|
||||
public static boolean isPerforceConfigured() throws InterruptedException
|
||||
{
|
||||
boolean result = false;
|
||||
obj_id self = getSelf();
|
||||
if (!isGod(self))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (hasObjVar(self, "P4USER"))
|
||||
{
|
||||
String perforceUserId = getStringObjVar(self, "P4USER");
|
||||
if (perforceUserId != null && perforceUserId.length() > 0)
|
||||
{
|
||||
if (hasObjVar(self, "P4PASSWD"))
|
||||
{
|
||||
String perforcePassword = getStringObjVar(self, "P4PASSWD");
|
||||
if (perforcePassword != null && perforcePassword.length() > 0)
|
||||
{
|
||||
result = system_process.runAndGetExitCode("p4 -P " + perforcePassword + " -u " + perforceUserId + " opened") == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static boolean isLocked(String fileName) throws InterruptedException
|
||||
{
|
||||
if (!isGod(getSelf()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
boolean result = false;
|
||||
if (whoLocked(fileName) != null)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static String whoLocked(String fileName) throws InterruptedException
|
||||
{
|
||||
if (!isGod(getSelf()))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String lockFileName = fileName + ".scriptlock";
|
||||
String lockContents = file_access.readTextFile(lockFileName);
|
||||
return lockContents;
|
||||
}
|
||||
public static boolean openExistingFileForExclusiveEdit(String fileName) throws InterruptedException
|
||||
{
|
||||
boolean result = false;
|
||||
obj_id self = getSelf();
|
||||
if (!isGod(self))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
String userId = getStringObjVar(self, "P4USER");
|
||||
String password = getStringObjVar(self, "P4PASSWD");
|
||||
if (isLocked(fileName))
|
||||
{
|
||||
String who = whoLocked(fileName);
|
||||
if (!who.equals(userId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (file_access.isWritable(fileName))
|
||||
{
|
||||
file_access.writeTextFile(fileName + ".scriptlock", userId);
|
||||
result = true;
|
||||
}
|
||||
else if (isPerforceConfigured())
|
||||
{
|
||||
if (system_process.runAndGetExitCode("p4 -P " + password + " -u " + userId + " edit " + fileName) == 0)
|
||||
{
|
||||
file_access.writeTextFile(fileName + ".scriptlock", userId);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static String[] opened() throws InterruptedException
|
||||
{
|
||||
if (!isPerforceConfigured())
|
||||
{
|
||||
setupPerforce();
|
||||
return null;
|
||||
}
|
||||
String[] result = null;
|
||||
obj_id self = getSelf();
|
||||
if (!isGod(self))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String userId = getStringObjVar(self, "P4USER");
|
||||
String password = getStringObjVar(self, "P4PASSWD");
|
||||
Runtime run = Runtime.getRuntime();
|
||||
if (run != null)
|
||||
{
|
||||
result = split(system_process.runAndGetOutput("p4 -P " + password + " -u " + userId + " opened"), '\n');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static void setupPerforce() throws InterruptedException
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
if (!isGod(self))
|
||||
{
|
||||
return;
|
||||
}
|
||||
int page = createSUIPage("/Script.perforceSetup", self, self);
|
||||
if (page >= 0)
|
||||
{
|
||||
subscribeToSUIEvent(page, sui_event_type.SET_onButton, "btnOk", "onPerforceSetupBtnOk");
|
||||
subscribeToSUIPropertyForEvent(page, sui_event_type.SET_onButton, "btnOk", "boxInputUserId.inputUserId", "LocalText");
|
||||
subscribeToSUIPropertyForEvent(page, sui_event_type.SET_onButton, "btnOk", "boxInputPassword.inputPassword", "LocalText");
|
||||
setSUIAssociatedObject(page, self);
|
||||
boolean showResult = showSUIPage(page);
|
||||
flushSUIPage(page);
|
||||
}
|
||||
}
|
||||
public static String change(int changeList) throws InterruptedException
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
if (!isGod(self))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String result = null;
|
||||
String userId = getStringObjVar(self, "P4USER");
|
||||
String password = getStringObjVar(self, "P4PASSWD");
|
||||
Runtime run = Runtime.getRuntime();
|
||||
if (run != null)
|
||||
{
|
||||
String cmdLine = "p4 -P " + password + " -u " + userId + " change -o";
|
||||
if (changeList != 0)
|
||||
{
|
||||
cmdLine += " " + changeList;
|
||||
}
|
||||
system_process p = new system_process(cmdLine);
|
||||
p.waitFor();
|
||||
if (p.getExitValue() == 0)
|
||||
{
|
||||
result = p.getOutput();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static String where(String fileLocation) throws InterruptedException
|
||||
{
|
||||
return system_process.runAndGetOutput("p4 " + getIdOptions() + " where " + fileLocation);
|
||||
}
|
||||
public static boolean submit(String changeDescription, Vector resultText) throws InterruptedException
|
||||
{
|
||||
if (!isGod(getSelf()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
String[] changeLines = split(changeDescription, '\n');
|
||||
int iter = 0;
|
||||
boolean readingFiles = false;
|
||||
Vector fileLocks = new Vector();
|
||||
for (iter = 0; iter < changeLines.length; ++iter)
|
||||
{
|
||||
if (readingFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
java.util.StringTokenizer st = new java.util.StringTokenizer(changeLines[iter], " \t\n");
|
||||
String first = st.nextToken();
|
||||
if (first != null)
|
||||
{
|
||||
String w = where(first);
|
||||
String[] locs = split(w, ' ');
|
||||
if (locs[2] != null)
|
||||
{
|
||||
String fileName = locs[2].trim();
|
||||
fileName += ".scriptlock";
|
||||
fileLocks.add(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(java.util.NoSuchElementException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (changeLines[iter].startsWith("Files:"))
|
||||
{
|
||||
readingFiles = true;
|
||||
}
|
||||
}
|
||||
obj_id self = getSelf();
|
||||
boolean result = false;
|
||||
String cmdLine = "p4 " + getIdOptions() + " submit -i";
|
||||
system_process p = new system_process(cmdLine);
|
||||
if (p != null)
|
||||
{
|
||||
p.putAndCloseInput(changeDescription);
|
||||
p.waitFor();
|
||||
if (p.getExitValue() == 0)
|
||||
{
|
||||
resultText.add(p.getOutput());
|
||||
for (iter = 0; iter < fileLocks.size(); ++iter)
|
||||
{
|
||||
File f = new File(((String)fileLocks.get(iter)));
|
||||
if (f.exists())
|
||||
{
|
||||
if (f.canWrite())
|
||||
{
|
||||
if (f.isFile())
|
||||
{
|
||||
if (!f.delete())
|
||||
{
|
||||
resultText.add("failed to remove lock " + ((String)fileLocks.get(iter)) + ": could not delete file");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resultText.add("failed to remove lock " + ((String)fileLocks.get(iter)) + ": not a file");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resultText.add(((String)fileLocks.get(iter)) + ": not writeable");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resultText.add("failed to remove file lock " + ((String)fileLocks.get(iter)) + ": it does not exist");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resultText.add(p.getOutput());
|
||||
resultText.add("Failed to execute " + cmdLine);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resultText.add("Could not execute " + cmdLine);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static String diff(String fileSpec) throws InterruptedException
|
||||
{
|
||||
if (!isGod(getSelf()))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String result = null;
|
||||
if (fileSpec != null)
|
||||
{
|
||||
result = system_process.runAndGetOutput("p4 " + getIdOptions() + " diff -dU150 " + fileSpec);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = system_process.runAndGetOutput("p4 " + getIdOptions() + " diff -dU150");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,299 +0,0 @@
|
||||
include java.lang.Runtime;
|
||||
include java.io.File;
|
||||
include java.io.InputStream;
|
||||
include java.io.OutputStream;
|
||||
include java.io.IOException;
|
||||
include library.chat;
|
||||
include developer.file_access;
|
||||
include java.io.InputStreamReader;
|
||||
include java.io.BufferedReader;
|
||||
|
||||
String getIdOptions()
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
if(! isGod(self))
|
||||
return null;
|
||||
|
||||
String userId = getStringObjVar(self, "P4USER");
|
||||
String password = getStringObjVar(self, "P4PASSWD");
|
||||
|
||||
return "-P " + password + " -u " + userId;
|
||||
}
|
||||
|
||||
boolean isPerforceConfigured()
|
||||
{
|
||||
boolean result = false;
|
||||
obj_id self = getSelf();
|
||||
if(! isGod(self))
|
||||
return false;
|
||||
|
||||
if(hasObjVar(self, "P4USER"))
|
||||
{
|
||||
String perforceUserId = getStringObjVar(self, "P4USER");
|
||||
if(perforceUserId != null && perforceUserId.length() > 0)
|
||||
{
|
||||
if(hasObjVar(self, "P4PASSWD"))
|
||||
{
|
||||
String perforcePassword = getStringObjVar(self, "P4PASSWD");
|
||||
if(perforcePassword != null && perforcePassword.length() > 0)
|
||||
{
|
||||
// perform a pretend sync to see if the user and password
|
||||
// are correct
|
||||
result = system_process.runAndGetExitCode("p4 -P " + perforcePassword + " -u " + perforceUserId + " opened") == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean isLocked(String fileName)
|
||||
{
|
||||
if(! isGod(getSelf()))
|
||||
return false;
|
||||
|
||||
boolean result = false;
|
||||
if(whoLocked(fileName) != null)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
String whoLocked(String fileName)
|
||||
{
|
||||
if(! isGod(getSelf()))
|
||||
return null;
|
||||
|
||||
String lockFileName = fileName + ".scriptlock";
|
||||
String lockContents = file_access.readTextFile(lockFileName);
|
||||
return lockContents;
|
||||
}
|
||||
|
||||
boolean openExistingFileForExclusiveEdit(String fileName)
|
||||
{
|
||||
boolean result = false;
|
||||
obj_id self = getSelf();
|
||||
if(! isGod(self))
|
||||
return false;
|
||||
|
||||
String userId = getStringObjVar(self, "P4USER");
|
||||
String password = getStringObjVar(self, "P4PASSWD");
|
||||
if(isLocked(fileName))
|
||||
{
|
||||
String who = whoLocked(fileName);
|
||||
if(who != userId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(file_access.isWritable(fileName))
|
||||
{
|
||||
file_access.writeTextFile(fileName + ".scriptlock", userId);
|
||||
result = true;
|
||||
}
|
||||
else if(isPerforceConfigured())
|
||||
{
|
||||
if(system_process.runAndGetExitCode("p4 -P " + password + " -u " + userId + " edit " + fileName) == 0)
|
||||
{
|
||||
file_access.writeTextFile(fileName + ".scriptlock", userId);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
String[] opened()
|
||||
{
|
||||
if(! isPerforceConfigured())
|
||||
{
|
||||
setupPerforce();
|
||||
return null;
|
||||
}
|
||||
String[] result = null;
|
||||
obj_id self = getSelf();
|
||||
if(! isGod(self))
|
||||
return null;
|
||||
|
||||
String userId = getStringObjVar(self, "P4USER");
|
||||
String password = getStringObjVar(self, "P4PASSWD");
|
||||
Runtime run = Runtime.getRuntime();
|
||||
if(run != null)
|
||||
{
|
||||
result = split(system_process.runAndGetOutput("p4 -P " + password + " -u " + userId + " opened"), '\n');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void setupPerforce()
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
|
||||
if(! isGod(self))
|
||||
return;
|
||||
|
||||
// popup perforce username/password page
|
||||
int page = createSUIPage("/Script.perforceSetup", self, self);
|
||||
if(page >= 0)
|
||||
{
|
||||
subscribeToSUIEvent(page, sui_event_type.SET_onButton, "btnOk", "onPerforceSetupBtnOk");
|
||||
subscribeToSUIPropertyForEvent(page, sui_event_type.SET_onButton, "btnOk", "boxInputUserId.inputUserId", "LocalText");
|
||||
subscribeToSUIPropertyForEvent(page, sui_event_type.SET_onButton, "btnOk", "boxInputPassword.inputPassword", "LocalText");
|
||||
setSUIAssociatedObject(page, self);
|
||||
boolean showResult = showSUIPage(page);
|
||||
flushSUIPage(page);
|
||||
}
|
||||
}
|
||||
|
||||
String change(int changeList)
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
if(! isGod(self))
|
||||
return null;
|
||||
|
||||
String result = null;
|
||||
String userId = getStringObjVar(self, "P4USER");
|
||||
String password = getStringObjVar(self, "P4PASSWD");
|
||||
Runtime run = Runtime.getRuntime();
|
||||
if(run != null)
|
||||
{
|
||||
String cmdLine = "p4 -P " + password + " -u " + userId + " change -o";
|
||||
if(changeList != 0)
|
||||
{
|
||||
cmdLine += " " + changeList;
|
||||
}
|
||||
system_process p = new system_process(cmdLine);
|
||||
p.waitFor();
|
||||
if(p.getExitValue() == 0)
|
||||
{
|
||||
result = p.getOutput();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
String where(String fileLocation)
|
||||
{
|
||||
return system_process.runAndGetOutput("p4 " + getIdOptions() + " where " + fileLocation);
|
||||
}
|
||||
|
||||
|
||||
boolean submit(String changeDescription, resizeable String[] resultText)
|
||||
{
|
||||
if(! isGod(getSelf()))
|
||||
return false;
|
||||
|
||||
// build a file list from the description
|
||||
String[] changeLines = split(changeDescription, '\n');
|
||||
int iter = 0;
|
||||
boolean readingFiles = false;
|
||||
resizeable String[] fileLocks = new Vector();
|
||||
for(iter = 0; iter < changeLines.length; ++iter)
|
||||
{
|
||||
if(readingFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
java.util.StringTokenizer st = new java.util.StringTokenizer(changeLines[iter], " \t\n");
|
||||
String first = st.nextToken();
|
||||
if(first != null)
|
||||
{
|
||||
String w = where(first);
|
||||
String[] locs = split(w, ' ');
|
||||
if(locs[2] != null)
|
||||
{
|
||||
String fileName = locs[2].trim();
|
||||
fileName += ".scriptlock";
|
||||
fileLocks.add(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(java.util.NoSuchElementException e)
|
||||
{
|
||||
// ignore lines that don't conform the the expected output
|
||||
}
|
||||
}
|
||||
else if(changeLines[iter].startsWith("Files:"))
|
||||
{
|
||||
readingFiles = true;
|
||||
}
|
||||
}
|
||||
|
||||
obj_id self = getSelf();
|
||||
boolean result = false;
|
||||
String cmdLine = "p4 " + getIdOptions() + " submit -i";
|
||||
system_process p = new system_process(cmdLine);
|
||||
if(p != null)
|
||||
{
|
||||
p.putAndCloseInput(changeDescription);
|
||||
p.waitFor();
|
||||
if(p.getExitValue() == 0)
|
||||
{
|
||||
resultText.add(p.getOutput());
|
||||
// remove file locks
|
||||
for(iter = 0; iter < fileLocks.length; ++iter)
|
||||
{
|
||||
File f = new File(fileLocks[iter]);
|
||||
if(f.exists())
|
||||
{
|
||||
if(f.canWrite())
|
||||
{
|
||||
if(f.isFile())
|
||||
{
|
||||
if(! f.delete())
|
||||
{
|
||||
resultText.add("failed to remove lock " + fileLocks[iter] + ": could not delete file");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resultText.add("failed to remove lock " + fileLocks[iter] + ": not a file");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resultText.add(fileLocks[iter] + ": not writeable");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resultText.add("failed to remove file lock " + fileLocks[iter] + ": it does not exist");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resultText.add(p.getOutput());
|
||||
resultText.add("Failed to execute " + cmdLine);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resultText.add("Could not execute " + cmdLine);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
String diff(String fileSpec)
|
||||
{
|
||||
if(! isGod(getSelf()))
|
||||
return null;
|
||||
|
||||
String result = null;
|
||||
if(fileSpec != null)
|
||||
{
|
||||
result = system_process.runAndGetOutput("p4 " + getIdOptions() + " diff -dU150 " + fileSpec);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = system_process.runAndGetOutput("p4 " + getIdOptions() + " diff -dU150");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
package script.developer;
|
||||
|
||||
import script.*;
|
||||
import script.base_class.*;
|
||||
import script.combat_engine.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import script.base_script;
|
||||
|
||||
import script.developer.perforce;
|
||||
import script.library.chat;
|
||||
import script.library.utils;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class perforce_user extends script.base_script
|
||||
{
|
||||
public perforce_user()
|
||||
{
|
||||
}
|
||||
public int OnSpeaking(obj_id self, String text) throws InterruptedException
|
||||
{
|
||||
if (!isGod(self))
|
||||
{
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
java.util.StringTokenizer st = new java.util.StringTokenizer(text);
|
||||
Vector args = new Vector();
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
args.add(st.nextToken());
|
||||
}
|
||||
if (!(((String)args.get(0)).equals("p4")))
|
||||
{
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
if (args.size() > 1 && ((String)args.get(1)).equals("login"))
|
||||
{
|
||||
perforce.setupPerforce();
|
||||
}
|
||||
else if (args.size() > 1 && ((String)args.get(1)).equals("edit"))
|
||||
{
|
||||
if (args.size() > 2)
|
||||
{
|
||||
String arg2 = ((String)args.get(2));
|
||||
perforce.openExistingFileForExclusiveEdit(arg2);
|
||||
}
|
||||
}
|
||||
else if (args.size() > 1 && ((String)args.get(1)).equals("opened"))
|
||||
{
|
||||
String[] results = perforce.opened();
|
||||
if (results != null)
|
||||
{
|
||||
String openedFiles = new String();
|
||||
int iter = 0;
|
||||
for (iter = 0; iter < results.length; ++iter)
|
||||
{
|
||||
openedFiles += results[iter] + "\n";
|
||||
}
|
||||
int page = createSUIPage("/Script.messageBox", self, self);
|
||||
setSUIProperty(page, "Prompt.lblPrompt", "LocalText", openedFiles);
|
||||
setSUIProperty(page, "bg.caption.lblTitle", "Text", "Perforce Opened");
|
||||
setSUIProperty(page, "Prompt.lblPrompt", "Editable", "false");
|
||||
setSUIProperty(page, "Prompt.lblPrompt", "GetsInput", "true");
|
||||
setSUIProperty(page, "btnCancel", "Visible", "false");
|
||||
setSUIProperty(page, "btnRevert", "Visible", "false");
|
||||
showSUIPage(page);
|
||||
flushSUIPage(page);
|
||||
}
|
||||
else
|
||||
{
|
||||
chat.chat(self, "there was an error retrieving the file listing");
|
||||
}
|
||||
}
|
||||
else if (args.size() > 1 && ((String)args.get(1)).equals("submit"))
|
||||
{
|
||||
String param = null;
|
||||
int changeList = 0;
|
||||
if (args.size() > 2)
|
||||
{
|
||||
param = ((String)args.get(2));
|
||||
}
|
||||
if (param != null)
|
||||
{
|
||||
changeList = utils.stringToInt(param);
|
||||
}
|
||||
String defaultChangeText = perforce.change(changeList);
|
||||
int page = createSUIPage("/Script.textEditor", self, self);
|
||||
setSUIProperty(page, "pageText.text", "LocalText", defaultChangeText);
|
||||
setSUIProperty(page, "bg.caption.text", "Text", "Perforce Submit");
|
||||
subscribeToSUIEvent(page, sui_event_type.SET_onButton, "btnOk", "onPerforceSubmitTextEditorBtnOk");
|
||||
subscribeToSUIPropertyForEvent(page, sui_event_type.SET_onButton, "btnOk", "pageText.text", "LocalText");
|
||||
showSUIPage(page);
|
||||
flushSUIPage(page);
|
||||
}
|
||||
else if (args.size() > 1 && ((String)args.get(1)).equals("diff"))
|
||||
{
|
||||
String param = null;
|
||||
int changeList = 0;
|
||||
if (args.size() > 2)
|
||||
{
|
||||
param = ((String)args.get(2));
|
||||
}
|
||||
String diff = perforce.diff(param);
|
||||
String[] diffLines = split(diff, '\n');
|
||||
String diffedText = new String("\\#FFFFFF");
|
||||
int iter = 0;
|
||||
for (iter = 0; iter < diffLines.length; ++iter)
|
||||
{
|
||||
if (diffLines[iter].startsWith("-"))
|
||||
{
|
||||
diffedText += "\\#FF0000" + diffLines[iter] + "\n" + "\\#FFFFFF";
|
||||
}
|
||||
else if (diffLines[iter].startsWith("+"))
|
||||
{
|
||||
diffedText += "\\#00FF00" + diffLines[iter] + "\n" + "\\#FFFFFF";
|
||||
}
|
||||
else
|
||||
{
|
||||
diffedText += diffLines[iter] + "\n" + "\\#FFFFFF";
|
||||
}
|
||||
}
|
||||
int page = createSUIPage("/Script.textEditor", self, self);
|
||||
setSUIProperty(page, "pageText.text", "LocalText", diffedText);
|
||||
setSUIProperty(page, "bg.caption.text", "Text", "Perforce Diff");
|
||||
setSUIProperty(page, "pageText.text", "Editable", "false");
|
||||
setSUIProperty(page, "pageText.text", "GetsInput", "true");
|
||||
setSUIProperty(page, "outputPage", "Visible", "false");
|
||||
setSUIProperty(page, "btnOk", "Visible", "false");
|
||||
setSUIProperty(page, "btnCancel", "Visible", "false");
|
||||
showSUIPage(page);
|
||||
flushSUIPage(page);
|
||||
}
|
||||
else if (args.size() < 2)
|
||||
{
|
||||
int page = createSUIPage("/Script.perforce", self, self);
|
||||
HashMap changes = new HashMap();
|
||||
String[] openedFiles = perforce.opened();
|
||||
String outputText = "p4 opened\n";
|
||||
int iter = 0;
|
||||
for (iter = 0; iter < openedFiles.length; ++iter)
|
||||
{
|
||||
String[] elems = split(openedFiles[iter], ' ');
|
||||
if (elems.length > 0)
|
||||
{
|
||||
String fileSpec = elems[0];
|
||||
if (elems.length > 2)
|
||||
{
|
||||
String action = elems[2];
|
||||
if (elems.length > 3)
|
||||
{
|
||||
String change = elems[3];
|
||||
if (change.equals("change") && elems.length > 4)
|
||||
{
|
||||
change = elems[4];
|
||||
}
|
||||
if (!changes.containsKey(change))
|
||||
{
|
||||
Vector files = new Vector();
|
||||
files.add(fileSpec);
|
||||
changes.put(change, files);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector files = (Vector)changes.get(change);
|
||||
files.add(fileSpec);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
outputText += openedFiles[iter] + "\n";
|
||||
}
|
||||
clearSUIDataSourceContainer(page, "changes.dataTree");
|
||||
Set keySet = changes.keySet();
|
||||
Iterator changesIter = keySet.iterator();
|
||||
while (changesIter.hasNext())
|
||||
{
|
||||
String key = (String)changesIter.next();
|
||||
Vector files = (Vector)changes.get(key);
|
||||
addSUIDataSourceContainer(page, "changes.dataTree", key);
|
||||
setSUIProperty(page, "changes.dataTree." + key, "text", key);
|
||||
for (iter = 0; iter < files.size(); ++iter)
|
||||
{
|
||||
String f = ((String)files.get(iter));
|
||||
addSUIDataSourceContainer(page, "changes.dataTree." + key, f);
|
||||
setSUIProperty(page, "changes.dataTree." + key + "." + f, "text", f);
|
||||
}
|
||||
}
|
||||
setSUIProperty(page, "outputPage.text", "LocalText", outputText);
|
||||
showSUIPage(page);
|
||||
flushSUIPage(page);
|
||||
return SCRIPT_OVERRIDE;
|
||||
}
|
||||
return SCRIPT_OVERRIDE;
|
||||
}
|
||||
public int onPerforceSetupBtnOk(obj_id self, dictionary params) throws InterruptedException
|
||||
{
|
||||
String userId = params.getString("boxInputUserId.inputUserId.LocalText");
|
||||
String password = params.getString("boxInputPassword.inputPassword.LocalText");
|
||||
setObjVar(self, "P4USER", userId);
|
||||
setObjVar(self, "P4PASSWD", password);
|
||||
forceCloseSUIPage(params.getInt("pageId"));
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
public int onPerforceSubmitTextEditorBtnOk(obj_id self, dictionary params) throws InterruptedException
|
||||
{
|
||||
int page = params.getInt("pageId");
|
||||
if (page < 0)
|
||||
{
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
String submissionContents = params.getString("pageText.text.LocalText");
|
||||
if (submissionContents == null || (submissionContents.length() < 1))
|
||||
{
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
Vector outputWindowText = new Vector();
|
||||
boolean submitSucceeded = perforce.submit(submissionContents, outputWindowText);
|
||||
String results = new String();
|
||||
if (submitSucceeded)
|
||||
{
|
||||
setSUIProperty(page, "pageText.text", "LocalText", "");
|
||||
setSUIProperty(page, "pageText.text", "Text", "");
|
||||
results += "\\##00FF00";
|
||||
}
|
||||
else
|
||||
{
|
||||
results += "\\##FF0000";
|
||||
}
|
||||
int iter = 0;
|
||||
for (iter = 0; iter < outputWindowText.size(); ++iter)
|
||||
{
|
||||
results += ((String)outputWindowText.get(iter)) + "\n";
|
||||
}
|
||||
setSUIProperty(page, "outputPage.text", "Text", results);
|
||||
flushSUIPage(page);
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
}
|
||||
@@ -1,249 +0,0 @@
|
||||
include developer.perforce;
|
||||
include library.chat;
|
||||
include library.utils;
|
||||
include java.util.HashMap;
|
||||
include java.util.Set;
|
||||
include java.util.Iterator;
|
||||
|
||||
trigger OnSpeaking(string text)
|
||||
{
|
||||
if(! isGod(self))
|
||||
return SCRIPT_CONTINUE;
|
||||
|
||||
java.util.StringTokenizer st = new java.util.StringTokenizer(text);
|
||||
resizeable String[] args = new Vector();
|
||||
while(st.hasMoreTokens())
|
||||
{
|
||||
args.add(st.nextToken());
|
||||
}
|
||||
|
||||
if(! (args[0].equals("p4")))
|
||||
{
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
|
||||
if(args.length > 1 && args[1].equals("login"))
|
||||
{
|
||||
perforce.setupPerforce();
|
||||
}
|
||||
else if(args.length > 1 && args[1].equals("edit"))
|
||||
{
|
||||
if(args.length > 2)
|
||||
{
|
||||
String arg2 = args[2];
|
||||
perforce.openExistingFileForExclusiveEdit(arg2);
|
||||
}
|
||||
}
|
||||
else if(args.length > 1 && args[1].equals("opened"))
|
||||
{
|
||||
//@todo : put this in a text box view
|
||||
String[] results = perforce.opened();
|
||||
if(results != null)
|
||||
{
|
||||
String openedFiles = new String();
|
||||
int iter = 0;
|
||||
for(iter = 0; iter < results.length; ++iter)
|
||||
{
|
||||
openedFiles += results[iter] + "\n";
|
||||
}
|
||||
|
||||
int page = createSUIPage("/Script.messageBox", self, self);
|
||||
setSUIProperty(page, "Prompt.lblPrompt", "LocalText", openedFiles);
|
||||
setSUIProperty(page, "bg.caption.lblTitle", "Text", "Perforce Opened");
|
||||
setSUIProperty(page, "Prompt.lblPrompt", "Editable", "false");
|
||||
setSUIProperty(page, "Prompt.lblPrompt", "GetsInput", "true");
|
||||
setSUIProperty(page, "btnCancel", "Visible", "false");
|
||||
setSUIProperty(page, "btnRevert", "Visible", "false");
|
||||
showSUIPage(page);
|
||||
flushSUIPage(page);
|
||||
}
|
||||
else
|
||||
{
|
||||
chat.chat(self, "there was an error retrieving the file listing");
|
||||
}
|
||||
}
|
||||
else if(args.length > 1 && args[1].equals("submit"))
|
||||
{
|
||||
String param = null;
|
||||
int changeList = 0;
|
||||
if(args.length > 2)
|
||||
{
|
||||
param = args[2];
|
||||
}
|
||||
|
||||
if(param != null)
|
||||
{
|
||||
changeList = utils.stringToInt(param);
|
||||
}
|
||||
|
||||
String defaultChangeText = perforce.change(changeList);
|
||||
int page = createSUIPage("/Script.textEditor", self, self);
|
||||
setSUIProperty(page, "pageText.text", "LocalText", defaultChangeText);
|
||||
setSUIProperty(page, "bg.caption.text", "Text", "Perforce Submit");
|
||||
subscribeToSUIEvent(page, sui_event_type.SET_onButton, "btnOk", "onPerforceSubmitTextEditorBtnOk");
|
||||
subscribeToSUIPropertyForEvent(page, sui_event_type.SET_onButton, "btnOk", "pageText.text", "LocalText");
|
||||
|
||||
showSUIPage(page);
|
||||
flushSUIPage(page);
|
||||
}
|
||||
else if(args.length > 1 && args[1].equals("diff"))
|
||||
{
|
||||
String param = null;
|
||||
int changeList = 0;
|
||||
if(args.length > 2)
|
||||
{
|
||||
param = args[2];
|
||||
}
|
||||
|
||||
String diff = perforce.diff(param);
|
||||
String[] diffLines = split(diff, '\n');
|
||||
String diffedText = new String("\\#FFFFFF");
|
||||
int iter = 0;
|
||||
for(iter = 0; iter < diffLines.length; ++iter)
|
||||
{
|
||||
if(diffLines[iter].startsWith("-"))
|
||||
{
|
||||
diffedText += "\\#FF0000" + diffLines[iter] + "\n" + "\\#FFFFFF";
|
||||
}
|
||||
else if(diffLines[iter].startsWith("+"))
|
||||
{
|
||||
diffedText += "\\#00FF00" + diffLines[iter] + "\n" + "\\#FFFFFF";
|
||||
}
|
||||
else
|
||||
{
|
||||
diffedText += diffLines[iter] + "\n" + "\\#FFFFFF";
|
||||
}
|
||||
}
|
||||
|
||||
int page = createSUIPage("/Script.textEditor", self, self);
|
||||
setSUIProperty(page, "pageText.text", "LocalText", diffedText);
|
||||
setSUIProperty(page, "bg.caption.text", "Text", "Perforce Diff");
|
||||
setSUIProperty(page, "pageText.text", "Editable", "false");
|
||||
setSUIProperty(page, "pageText.text", "GetsInput", "true");
|
||||
setSUIProperty(page, "outputPage", "Visible", "false");
|
||||
setSUIProperty(page, "btnOk", "Visible", "false");
|
||||
setSUIProperty(page, "btnCancel", "Visible", "false");
|
||||
showSUIPage(page);
|
||||
flushSUIPage(page);
|
||||
}
|
||||
else if(args.length < 2)
|
||||
{
|
||||
int page = createSUIPage("/Script.perforce", self, self);
|
||||
HashMap changes = new HashMap();
|
||||
// get a list of opened files
|
||||
String[] openedFiles = perforce.opened();
|
||||
String outputText = "p4 opened\n";
|
||||
int iter = 0;
|
||||
for(iter = 0; iter < openedFiles.length; ++iter)
|
||||
{
|
||||
String[] elems = split(openedFiles[iter], ' ');
|
||||
if(elems.length > 0)
|
||||
{
|
||||
String fileSpec = elems[0];
|
||||
if(elems.length > 2)
|
||||
{
|
||||
String action = elems[2];
|
||||
if(elems.length > 3)
|
||||
{
|
||||
String change = elems[3];
|
||||
if(change == "change" && elems.length > 4)
|
||||
{
|
||||
change = elems[4];
|
||||
}
|
||||
|
||||
if(! changes.containsKey(change))
|
||||
{
|
||||
resizeable String[] files = new Vector();
|
||||
files.add(fileSpec);
|
||||
changes.put(change, files);
|
||||
}
|
||||
else
|
||||
{
|
||||
resizeable String[] files = (Vector)changes.get(change);
|
||||
files.add(fileSpec);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
outputText += openedFiles[iter] + "\n";
|
||||
}
|
||||
|
||||
clearSUIDataSourceContainer(page, "changes.dataTree");
|
||||
|
||||
Set keySet = changes.keySet();
|
||||
Iterator changesIter = keySet.iterator();
|
||||
while(changesIter.hasNext())
|
||||
{
|
||||
String key = (String)changesIter.next();
|
||||
resizeable String[] files = (Vector)changes.get(key);
|
||||
addSUIDataSourceContainer(page, "changes.dataTree", key);
|
||||
setSUIProperty(page, "changes.dataTree." + key, "text", key);
|
||||
for(iter = 0; iter < files.length; ++iter)
|
||||
{
|
||||
String f = files[iter];
|
||||
addSUIDataSourceContainer(page, "changes.dataTree." + key, f);
|
||||
setSUIProperty(page, "changes.dataTree." + key + "." + f, "text", f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
setSUIProperty(page, "outputPage.text", "LocalText", outputText);
|
||||
showSUIPage(page);
|
||||
flushSUIPage(page);
|
||||
return SCRIPT_OVERRIDE;
|
||||
}
|
||||
|
||||
return SCRIPT_OVERRIDE;
|
||||
}
|
||||
|
||||
messageHandler onPerforceSetupBtnOk()
|
||||
{
|
||||
String userId = params.getString("boxInputUserId.inputUserId.LocalText");
|
||||
String password = params.getString("boxInputPassword.inputPassword.LocalText");
|
||||
setObjVar(self, "P4USER", userId);
|
||||
setObjVar(self, "P4PASSWD", password);
|
||||
forceCloseSUIPage(params.getInt("pageId"));
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
|
||||
messageHandler onPerforceSubmitTextEditorBtnOk()
|
||||
{
|
||||
int page = params.getInt("pageId");
|
||||
if(page < 0)
|
||||
{
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
|
||||
String submissionContents = params.getString("pageText.text.LocalText");
|
||||
if(submissionContents == null || (submissionContents.length() < 1))
|
||||
{
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
resizeable String[] outputWindowText = new Vector();
|
||||
boolean submitSucceeded = perforce.submit(submissionContents, outputWindowText);
|
||||
String results = new String();
|
||||
if(submitSucceeded)
|
||||
{
|
||||
setSUIProperty(page, "pageText.text", "LocalText", "");
|
||||
setSUIProperty(page, "pageText.text", "Text", "");
|
||||
results += "\\##00FF00";
|
||||
}
|
||||
else
|
||||
{
|
||||
results += "\\##FF0000";
|
||||
}
|
||||
|
||||
int iter = 0;
|
||||
for(iter = 0; iter < outputWindowText.length; ++iter)
|
||||
{
|
||||
results += outputWindowText[iter] + "\n";
|
||||
}
|
||||
|
||||
|
||||
setSUIProperty(page, "outputPage.text", "Text", results);
|
||||
flushSUIPage(page);
|
||||
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
package script.developer;
|
||||
|
||||
import script.*;
|
||||
import script.base_class.*;
|
||||
import script.combat_engine.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import script.base_script;
|
||||
|
||||
import script.developer.file_access;
|
||||
import script.library.utils;
|
||||
import java.io.InputStream;
|
||||
import script.library.chat;
|
||||
import java.util.Date;
|
||||
|
||||
public class script_editor extends script.base_script
|
||||
{
|
||||
public script_editor()
|
||||
{
|
||||
}
|
||||
public int OnSpeaking(obj_id self, String text) throws InterruptedException
|
||||
{
|
||||
if (!isGod(self))
|
||||
{
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
if (!text.startsWith("editScript"))
|
||||
{
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
java.util.StringTokenizer st = new java.util.StringTokenizer(text);
|
||||
st.nextToken();
|
||||
String params = st.nextToken();
|
||||
if (params == null)
|
||||
{
|
||||
sendSystemMessageTestingOnly(self, "Usage: /editScript <script name> e.g. /editScript justin.test_scriptedit");
|
||||
return SCRIPT_OVERRIDE;
|
||||
}
|
||||
if (params.length() < 1)
|
||||
{
|
||||
sendSystemMessageTestingOnly(self, "Usage: /editScript <script name> e.g. /editScript justin.test_scriptedit");
|
||||
return SCRIPT_OVERRIDE;
|
||||
}
|
||||
String scriptBaseName = params;
|
||||
String prefix = "../../dsrc/sku.0/sys.server/compiled/game/script";
|
||||
String classPrefix = "../../data/sku.0/sys.server/compiled/game/script";
|
||||
String[] path = split(scriptBaseName, '.');
|
||||
String scriptClassName = classPrefix;
|
||||
String scriptFileName = prefix;
|
||||
int iter = 0;
|
||||
for (iter = 0; iter < path.length; ++iter)
|
||||
{
|
||||
scriptFileName += "/" + path[iter];
|
||||
}
|
||||
for (iter = 0; iter < path.length; ++iter)
|
||||
{
|
||||
scriptClassName += "/" + path[iter];
|
||||
}
|
||||
scriptClassName += ".class";
|
||||
scriptFileName += ".script";
|
||||
String scriptContents = file_access.readTextFile(scriptFileName);
|
||||
if (scriptContents == null)
|
||||
{
|
||||
scriptFileName += "lib";
|
||||
scriptContents = file_access.readTextFile(scriptFileName);
|
||||
}
|
||||
if (scriptContents == null)
|
||||
{
|
||||
sendSystemMessageTestingOnly(self, "Could not get script contents from " + scriptBaseName + ".script or " + scriptBaseName + ".scriptlib");
|
||||
return SCRIPT_OVERRIDE;
|
||||
}
|
||||
int page = createSUIPage("/Script.editScript", self, self);
|
||||
setSUIProperty(page, "pageText.text", "Text", scriptContents);
|
||||
setSUIProperty(page, "bg.caption.text", "LocalText", "EDIT SCRIPT - " + scriptBaseName);
|
||||
subscribeToSUIEvent(page, sui_event_type.SET_onButton, "btnOk", "onScriptEditBtnOk");
|
||||
subscribeToSUIPropertyForEvent(page, sui_event_type.SET_onButton, "btnOk", "pageText.text", "LocalText");
|
||||
subscribeToSUIPropertyForEvent(page, sui_event_type.SET_onButton, "btnOk", "outputPage.text", "LocalText");
|
||||
setSUIAssociatedObject(page, self);
|
||||
boolean showResult = showSUIPage(page);
|
||||
flushSUIPage(page);
|
||||
String trackPage = "scriptFileName" + page;
|
||||
utils.setScriptVar(self, trackPage, scriptFileName);
|
||||
String trackScriptName = "scriptBase" + page;
|
||||
utils.setScriptVar(self, trackScriptName, scriptBaseName);
|
||||
String trackClassName = "classBase" + page;
|
||||
utils.setScriptVar(self, trackClassName, scriptClassName);
|
||||
return SCRIPT_OVERRIDE;
|
||||
}
|
||||
public int onScriptEditBtnOk(obj_id self, dictionary params) throws InterruptedException
|
||||
{
|
||||
if (!isGod(self))
|
||||
{
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
String scriptContents = params.getString("pageText.text.LocalText");
|
||||
if (scriptContents == null)
|
||||
{
|
||||
sendSystemMessageTestingOnly(self, "could not get script contents from the client");
|
||||
}
|
||||
String outputWindowText = new String();
|
||||
if (params.getString("outputPage.text.LocalText") != null)
|
||||
{
|
||||
}
|
||||
if (scriptContents.length() > 0)
|
||||
{
|
||||
int pageId = params.getInt("pageId");
|
||||
if (pageId >= 0)
|
||||
{
|
||||
String scriptFileNameKey = "scriptFileName" + pageId;
|
||||
if (scriptFileNameKey != null)
|
||||
{
|
||||
String scriptFileName = utils.getStringScriptVar(self, scriptFileNameKey);
|
||||
if (scriptFileName != null)
|
||||
{
|
||||
outputWindowText += "--== Compiling " + scriptFileName + " ==--\n";
|
||||
|
||||
{
|
||||
String scriptNameScriptVar = "scriptBase" + pageId;
|
||||
String scriptName = utils.getStringScriptVar(self, scriptNameScriptVar);
|
||||
String classNameScriptVar = "classBase" + pageId;
|
||||
String className = utils.getStringScriptVar(self, classNameScriptVar);
|
||||
|
||||
{
|
||||
if (file_access.writeTextFile(scriptFileName, scriptContents))
|
||||
{
|
||||
Runtime run = Runtime.getRuntime();
|
||||
if (run != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
String outputString = system_process.runAndGetOutput("nge-swg-master/utils/mocha/script_prep2.py -i " + scriptFileName);
|
||||
if (outputString != null)
|
||||
{
|
||||
outputWindowText += outputString + "\n";
|
||||
}
|
||||
if (scriptName != null)
|
||||
{
|
||||
if (reloadScript(scriptName))
|
||||
{
|
||||
Date d = new Date();
|
||||
outputWindowText += "Script " + scriptName + " reloaded successfully at " + d + "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
outputWindowText += "*** ERROR: Could not reload " + scriptName + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
outputWindowText += "*** ERROR: An exception occurred while trying to compile " + scriptFileName + " : " + e + "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
outputWindowText += "*** ERROR: could not get runtime\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
outputWindowText += "*** ERROR: could not write " + scriptFileName + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
outputWindowText += "*** ERROR: could not retrieve script file name from " + scriptFileNameKey + "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
outputWindowText += "*** ERROR: could not create file name key \"scriptFileName" + pageId + "\"\n";
|
||||
}
|
||||
setSUIProperty(pageId, "outputPage.text", "Text", outputWindowText);
|
||||
boolean showResult = showSUIPage(pageId);
|
||||
flushSUIPage(pageId);
|
||||
}
|
||||
}
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
include developer.file_access;
|
||||
include library.utils;
|
||||
include java.io.InputStream;
|
||||
include library.chat;
|
||||
include java.util.Date;
|
||||
|
||||
// todo: make this a command handler
|
||||
trigger OnSpeaking(string text)
|
||||
{
|
||||
if(! isGod(self))
|
||||
return SCRIPT_CONTINUE;
|
||||
|
||||
if(! text.startsWith("editScript"))
|
||||
return SCRIPT_CONTINUE;
|
||||
|
||||
java.util.StringTokenizer st = new java.util.StringTokenizer(text);
|
||||
|
||||
st.nextToken();
|
||||
String params = st.nextToken();
|
||||
|
||||
// validate the parameter string, it should be the name of a script to edit
|
||||
if(params == null)
|
||||
{
|
||||
sendSystemMessageTestingOnly(self, "Usage: /editScript <script name> e.g. /editScript justin.test_scriptedit");
|
||||
return SCRIPT_OVERRIDE;
|
||||
}
|
||||
|
||||
if(params.length() < 1)
|
||||
{
|
||||
sendSystemMessageTestingOnly(self, "Usage: /editScript <script name> e.g. /editScript justin.test_scriptedit");
|
||||
return SCRIPT_OVERRIDE;
|
||||
}
|
||||
|
||||
// get script file name
|
||||
String scriptBaseName = params;
|
||||
String prefix = "../../dsrc/sku.0/sys.server/compiled/game/script";
|
||||
String classPrefix = "../../data/sku.0/sys.server/compiled/game/script";
|
||||
String[] path = split(scriptBaseName, '.');
|
||||
String scriptClassName = classPrefix;
|
||||
String scriptFileName = prefix;
|
||||
|
||||
// convert .'s to /'s
|
||||
int iter = 0;
|
||||
for(iter = 0; iter < path.length; ++iter)
|
||||
{
|
||||
scriptFileName += "/" + path[iter];
|
||||
}
|
||||
|
||||
for(iter = 0; iter < path.length; ++iter)
|
||||
{
|
||||
scriptClassName += "/" + path[iter];
|
||||
}
|
||||
|
||||
scriptClassName += ".class";
|
||||
|
||||
// append the script source extension
|
||||
scriptFileName += ".script";
|
||||
|
||||
String scriptContents = file_access.readTextFile(scriptFileName);
|
||||
if(scriptContents == null)
|
||||
{
|
||||
// if the file could not be opened, try a .scriptlib
|
||||
scriptFileName += "lib";
|
||||
scriptContents = file_access.readTextFile(scriptFileName);
|
||||
}
|
||||
|
||||
if(scriptContents == null)
|
||||
{
|
||||
// the file does not exist, advise the user
|
||||
sendSystemMessageTestingOnly(self, "Could not get script contents from " + scriptBaseName + ".script or " + scriptBaseName + ".scriptlib");
|
||||
return SCRIPT_OVERRIDE;
|
||||
}
|
||||
|
||||
// create the user interface
|
||||
int page = createSUIPage("/Script.editScript", self, self);
|
||||
|
||||
// put the contents of the script on the page
|
||||
setSUIProperty(page, "pageText.text", "Text", scriptContents);
|
||||
setSUIProperty(page, "bg.caption.text", "LocalText", "EDIT SCRIPT - " + scriptBaseName);
|
||||
// listen for a user request to send the script contents
|
||||
// to the server for a recompile and reload
|
||||
subscribeToSUIEvent(page, sui_event_type.SET_onButton, "btnOk", "onScriptEditBtnOk");
|
||||
subscribeToSUIPropertyForEvent(page, sui_event_type.SET_onButton, "btnOk", "pageText.text", "LocalText");
|
||||
|
||||
// also track the output window. Error/standard out from the
|
||||
// script compile process will be appended to it
|
||||
subscribeToSUIPropertyForEvent(page, sui_event_type.SET_onButton, "btnOk", "outputPage.text", "LocalText");
|
||||
|
||||
setSUIAssociatedObject(page, self);
|
||||
boolean showResult = showSUIPage(page);
|
||||
flushSUIPage(page);
|
||||
|
||||
// setup tracking info for this UI page
|
||||
String trackPage = "scriptFileName" + page;
|
||||
utils.setScriptVar(self, trackPage, scriptFileName);
|
||||
String trackScriptName = "scriptBase" + page;
|
||||
utils.setScriptVar(self, trackScriptName, scriptBaseName);
|
||||
String trackClassName = "classBase" + page;
|
||||
utils.setScriptVar(self, trackClassName, scriptClassName);
|
||||
return SCRIPT_OVERRIDE;
|
||||
}
|
||||
|
||||
messageHandler onScriptEditBtnOk()
|
||||
{
|
||||
if(!isGod(self))
|
||||
return SCRIPT_CONTINUE;
|
||||
|
||||
String scriptContents = params.getString("pageText.text.LocalText");
|
||||
if(scriptContents == null)
|
||||
{
|
||||
sendSystemMessageTestingOnly(self, "could not get script contents from the client");
|
||||
}
|
||||
|
||||
String outputWindowText = new String();
|
||||
if(params.getString("outputPage.text.LocalText") != null)
|
||||
{
|
||||
//outputWindowText += params.getString("outputPage.text.LocalText");
|
||||
}
|
||||
|
||||
if(scriptContents.length() > 0)
|
||||
{
|
||||
// compile and reload the script!
|
||||
int pageId = params.getInt("pageId");
|
||||
if(pageId >= 0)
|
||||
{
|
||||
String scriptFileNameKey = "scriptFileName" + pageId;
|
||||
if(scriptFileNameKey != null)
|
||||
{
|
||||
String scriptFileName = utils.getStringScriptVar(self, scriptFileNameKey);
|
||||
if(scriptFileName != null)
|
||||
{
|
||||
outputWindowText += "--== Compiling " + scriptFileName + " ==--\n";
|
||||
/*if(! perforce.openExistingFileForExclusiveEdit(scriptFileName))
|
||||
{
|
||||
outputWindowText += "*** ERROR: Could not edit/lock " + scriptFileName + "\n";
|
||||
}
|
||||
else */
|
||||
{
|
||||
String scriptNameScriptVar = "scriptBase" + pageId;
|
||||
String scriptName = utils.getStringScriptVar(self, scriptNameScriptVar);
|
||||
|
||||
// open the class file!
|
||||
String classNameScriptVar = "classBase" + pageId;
|
||||
String className = utils.getStringScriptVar(self, classNameScriptVar);
|
||||
/*if(! perforce.openExistingFileForExclusiveEdit(className))
|
||||
{
|
||||
outputWindowText += "*** ERROR: Could not edit/lock " + className + "\n";
|
||||
}
|
||||
else */
|
||||
{
|
||||
if(file_access.writeTextFile(scriptFileName, scriptContents))
|
||||
{
|
||||
Runtime run = Runtime.getRuntime();
|
||||
if(run != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
String outputString = system_process.runAndGetOutput("nge-swg-master/utils/mocha/script_prep2.py -i " + scriptFileName);
|
||||
|
||||
|
||||
if(outputString != null)
|
||||
outputWindowText += outputString + "\n";
|
||||
|
||||
// reload the script
|
||||
if(scriptName != null)
|
||||
{
|
||||
if(reloadScript(scriptName))
|
||||
{
|
||||
Date d = new Date();
|
||||
outputWindowText += "Script " + scriptName + " reloaded successfully at " + d + "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
outputWindowText += "*** ERROR: Could not reload " + scriptName + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
outputWindowText += "*** ERROR: An exception occurred while trying to compile " + scriptFileName + " : " + e + "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
outputWindowText += "*** ERROR: could not get runtime\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
outputWindowText += "*** ERROR: could not write " + scriptFileName + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
outputWindowText += "*** ERROR: could not retrieve script file name from " + scriptFileNameKey + "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
outputWindowText += "*** ERROR: could not create file name key \"scriptFileName" + pageId + "\"\n";
|
||||
}
|
||||
setSUIProperty(pageId, "outputPage.text", "Text", outputWindowText);
|
||||
boolean showResult = showSUIPage(pageId);
|
||||
flushSUIPage(pageId);
|
||||
}
|
||||
}
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
Reference in New Issue
Block a user