385 lines
11 KiB
C#
385 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Xml.Linq;
|
|
using System.Xml.Serialization;
|
|
using UAF;
|
|
using UAF.WPF.Models;
|
|
using UAF.Perforce;
|
|
|
|
|
|
namespace ConfigurePlus.Models
|
|
{
|
|
[TypeConverter(typeof(ConfigurePlus.Converters.ProjectTypeConverter))]
|
|
public class ProjectViewModel : DataModelBase
|
|
{
|
|
protected string m_projectId;
|
|
protected string m_branchName;
|
|
protected string m_gameName;
|
|
protected string m_name;
|
|
protected string m_dataPath;
|
|
protected string m_enginePath;
|
|
protected string m_perforceServer;
|
|
protected string m_perforceUser;
|
|
protected string m_perforceClient;
|
|
protected string m_fieldsDescriptor;
|
|
protected EngineStartMode m_engineStartMode;
|
|
protected string m_iconUri;
|
|
protected bool m_globalProject;
|
|
protected LockedFields m_readOnlyFields = LockedFields.None;
|
|
|
|
private ObservableCollection<string> m_availableClients = new ObservableCollection<string>();
|
|
|
|
public string ProjectId
|
|
{
|
|
get { return m_projectId; }
|
|
set
|
|
{
|
|
if (m_projectId != value)
|
|
{
|
|
m_projectId = value;
|
|
RaisePropertyChanged("ProjectId");
|
|
}
|
|
}
|
|
}
|
|
|
|
public string BranchName
|
|
{
|
|
get { return m_branchName; }
|
|
set
|
|
{
|
|
if (m_branchName != value)
|
|
{
|
|
m_branchName = value;
|
|
RaisePropertyChanged("BranchName");
|
|
UpdateProjectId();
|
|
}
|
|
}
|
|
}
|
|
|
|
public string GameName
|
|
{
|
|
get { return m_gameName; }
|
|
set
|
|
{
|
|
if (m_gameName != value)
|
|
{
|
|
m_gameName = value;
|
|
RaisePropertyChanged("GameName");
|
|
UpdateProjectId();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateProjectId()
|
|
{
|
|
if (!string.IsNullOrEmpty(m_branchName))
|
|
{
|
|
m_projectId = string.Format("{0}_{1}", m_gameName, m_branchName);
|
|
}
|
|
else
|
|
{
|
|
m_projectId = m_gameName;
|
|
}
|
|
RaisePropertyChanged("ProjectId");
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get { return m_name; }
|
|
set
|
|
{
|
|
if (m_name != value)
|
|
{
|
|
m_name = value;
|
|
RaisePropertyChanged("Name");
|
|
}
|
|
}
|
|
}
|
|
|
|
public string DataPath
|
|
{
|
|
get { return m_dataPath; }
|
|
set
|
|
{
|
|
if (m_dataPath != value)
|
|
{
|
|
m_dataPath = value;
|
|
RaisePropertyChanged("DataPath");
|
|
}
|
|
}
|
|
}
|
|
|
|
public string EnginePath
|
|
{
|
|
get { return m_enginePath; }
|
|
set
|
|
{
|
|
if (m_enginePath != value)
|
|
{
|
|
m_enginePath = value;
|
|
RaisePropertyChanged("EnginePath");
|
|
}
|
|
}
|
|
}
|
|
|
|
public string PerforceServer
|
|
{
|
|
get { return m_perforceServer; }
|
|
set
|
|
{
|
|
if (m_perforceServer != value)
|
|
{
|
|
m_perforceServer = value;
|
|
RaisePropertyChanged("PerforceServer");
|
|
}
|
|
}
|
|
}
|
|
|
|
public string PerforceUser
|
|
{
|
|
get { return m_perforceUser; }
|
|
set
|
|
{
|
|
if (m_perforceUser != value)
|
|
{
|
|
m_perforceUser = value;
|
|
RaisePropertyChanged("PerforceUser");
|
|
}
|
|
}
|
|
}
|
|
|
|
public string PerforceClient
|
|
{
|
|
get { return m_perforceClient; }
|
|
set
|
|
{
|
|
if (m_perforceClient != value)
|
|
{
|
|
m_perforceClient = value;
|
|
RaisePropertyChanged("PerforceClient");
|
|
}
|
|
}
|
|
}
|
|
|
|
public ObservableCollection<string> AvailableClients
|
|
{
|
|
get { return m_availableClients; }
|
|
}
|
|
|
|
public EngineStartMode EngineStartMode
|
|
{
|
|
get { return m_engineStartMode; }
|
|
set
|
|
{
|
|
if (m_engineStartMode != value)
|
|
{
|
|
m_engineStartMode = value;
|
|
RaisePropertyChanged("EngineStartMode");
|
|
}
|
|
}
|
|
}
|
|
|
|
public string FieldsDescriptor
|
|
{
|
|
get { return m_fieldsDescriptor; }
|
|
set
|
|
{
|
|
if (m_fieldsDescriptor != value)
|
|
{
|
|
m_fieldsDescriptor = value;
|
|
RaisePropertyChanged("FieldsDescriptor");
|
|
}
|
|
}
|
|
}
|
|
|
|
public string IconUri
|
|
{
|
|
get { return m_iconUri; }
|
|
set
|
|
{
|
|
if (m_iconUri != value)
|
|
{
|
|
m_iconUri = value;
|
|
RaisePropertyChanged("IconUri");
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IsGlobalProject
|
|
{
|
|
get { return m_globalProject; }
|
|
set { m_globalProject = value; }
|
|
}
|
|
|
|
public virtual XElement SerializeProject()
|
|
{
|
|
return this.ToXml();
|
|
}
|
|
|
|
public void Update(ProjectViewModel sourceProject)
|
|
{
|
|
IconUri = sourceProject.IconUri;
|
|
ReadOnlyFields = sourceProject.ReadOnlyFields;
|
|
Type myType = GetType();
|
|
|
|
foreach (string fieldName in Enum.GetNames(typeof(LockedFields)))
|
|
{
|
|
LockedFields curFlag = (LockedFields)Enum.Parse(typeof(LockedFields), fieldName);
|
|
if ((curFlag != LockedFields.None) && (sourceProject.ReadOnlyFields & curFlag) == curFlag)
|
|
{
|
|
System.Reflection.PropertyInfo propertyInfo = myType.GetProperty(fieldName);
|
|
object newValue = propertyInfo.GetValue(sourceProject, null);
|
|
propertyInfo.SetValue(this, newValue, null);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpdateLockedFields()
|
|
{
|
|
LockedFields lockedFields = LockedFields.None;
|
|
Type myType = GetType();
|
|
|
|
foreach(string fieldName in Enum.GetNames(typeof(LockedFields)))
|
|
{
|
|
System.Reflection.PropertyInfo propertyInfo = myType.GetProperty(fieldName);
|
|
if(propertyInfo != null)
|
|
{
|
|
if(propertyInfo.GetValue(this, null) != null)
|
|
lockedFields |= (LockedFields) Enum.Parse(typeof(LockedFields), fieldName);
|
|
}
|
|
}
|
|
|
|
ReadOnlyFields = lockedFields;
|
|
}
|
|
|
|
public void AutoFillProject()
|
|
{
|
|
PerforceManager.Instance.InitPerforceWrapper(PerforceServer);
|
|
if (PerforceManager.Instance.IsWrapperReady)
|
|
{
|
|
PerforceUser = PerforceManager.Instance.User;
|
|
PerforceClient = PerforceManager.Instance.Client;
|
|
}
|
|
|
|
if (DataPath == null)
|
|
{
|
|
string currentDir = Directory.GetCurrentDirectory();
|
|
DirectoryInfo dir = new DirectoryInfo(currentDir);
|
|
DataPath = dir.Parent.Parent.FullName + "\\data";
|
|
}
|
|
|
|
if (EnginePath == null)
|
|
{
|
|
string currentDir = Directory.GetCurrentDirectory();
|
|
DirectoryInfo dir = new DirectoryInfo(currentDir);
|
|
EnginePath = dir.Parent.Parent.FullName + "\\engine";
|
|
}
|
|
}
|
|
|
|
public UAF.Project ToEngineBranch()
|
|
{
|
|
return (UAF.Project) TypeDescriptor.GetConverter(typeof(ProjectViewModel)).ConvertTo(this, typeof(UAF.Project));
|
|
}
|
|
|
|
private bool CreatePerforceProcess(string _command, List<string> _resultLineList, string _input)
|
|
{
|
|
//Declare and instantiate a new process component.
|
|
Process process = new Process();
|
|
|
|
process.StartInfo.FileName = "CMD.exe";
|
|
process.StartInfo.Arguments = "/C " + _command;
|
|
process.StartInfo.CreateNoWindow = true;
|
|
|
|
Console.Write("{0} {1}\n", process.StartInfo.FileName, process.StartInfo.Arguments);
|
|
|
|
//process.EnableRaisingEvents = false;
|
|
process.StartInfo.UseShellExecute = false;
|
|
process.StartInfo.RedirectStandardOutput = true;
|
|
process.StartInfo.RedirectStandardInput = (_input != null);
|
|
|
|
process.Start();
|
|
|
|
if (_input != null)
|
|
{
|
|
process.StandardInput.WriteLine(_input);
|
|
process.StandardInput.Close();
|
|
}
|
|
|
|
while (!process.StandardOutput.EndOfStream)
|
|
_resultLineList.Add(process.StandardOutput.ReadLine());
|
|
|
|
process.WaitForExit();
|
|
process.Close();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
[XmlIgnore]
|
|
public LockedFields ReadOnlyFields
|
|
{
|
|
get { return m_readOnlyFields; }
|
|
set
|
|
{
|
|
if (m_readOnlyFields != value)
|
|
{
|
|
m_readOnlyFields = value;
|
|
RaisePropertyChanged("ReadOnlyFields");
|
|
}
|
|
}
|
|
}
|
|
|
|
[Flags]
|
|
public enum LockedFields
|
|
{
|
|
None = 0,
|
|
ProjectId = 1 << 0,
|
|
Name = 1 << 1,
|
|
DataPath = 1 << 2,
|
|
EnginePath = 1 << 3,
|
|
PerforceServer = 1 << 4,
|
|
PerforceUser = 1 << 5,
|
|
PerforceClient = 1 << 6,
|
|
FieldsDescriptor = 1 << 7,
|
|
EngineStartMode = 1 << 8,
|
|
GameName = 1 << 9,
|
|
BranchName = 1 << 10,
|
|
|
|
}
|
|
}
|
|
|
|
public enum EngineStartMode
|
|
{
|
|
UA_Engine = 0,
|
|
UA_Framework = 1,
|
|
}
|
|
|
|
public class TestProject : ProjectViewModel
|
|
{
|
|
public TestProject()
|
|
{
|
|
m_projectId = "MYCODE";
|
|
m_dataPath = "Data path";
|
|
m_enginePath = "Engine path";
|
|
m_engineStartMode = EngineStartMode.UA_Engine;
|
|
m_fieldsDescriptor = "";
|
|
m_iconUri = null;
|
|
m_name = "Test Project";
|
|
m_perforceClient = "My Perforce Client";
|
|
m_perforceServer = "My Perforce Server";
|
|
m_perforceUser = "My Perforce User";
|
|
}
|
|
|
|
public override XElement SerializeProject()
|
|
{
|
|
return this.ToXml();
|
|
}
|
|
}
|
|
|
|
}
|