using UnityEditor; using UnityEngine; using System; using System.Collections.Generic; using System.Linq; using System.Text; using Perforce.P4; namespace P4Connect { /// <summary> /// A collection of static methods that allow us to check the perforce connection settings /// </summary> public class VerifySettings { public static string LastWorkspaceMapping; /// <summary> /// Checks whether the source control setting is correct /// </summary> /// <returns></returns> public static bool CheckMetaFiles() { return EditorSettings.externalVersionControl.Contains("Meta Files"); } /// <summary> /// Checks that the DLL file to talk to P4API.NET exists /// </summary> //public static bool CheckDLLLocation() //{ // Just check that the file exists at that location // return System.IO.File.Exists(System.IO.Path.Combine(System.IO.Path.Combine(Application.dataPath, Config.DLLLocation), Config.P4BridgeDLLName)); //} /// <summary> /// Checks that the server is reachable /// </summary> public static bool CheckServerURI() { // Build a server object and try to connect to it bool serverValid = false; Server testServer = new Server(new ServerAddress(Config.ServerURI)); Repository depot = new Repository(testServer); Connection con = depot.Connection; if (Config.OverrideHostname) { System.Environment.SetEnvironmentVariable("P4HOST", Config.Hostname); } try { // Attempt to connect con.Connect(null); con.Trust(new TrustCmdOptions(TrustCmdFlags.AutoAccept), ""); // If that didn't throw an exception, make sure the server is reported as online serverValid = (testServer.State == ServerState.Online); con.Disconnect(); } catch (P4Exception) { serverValid = false; } System.Environment.SetEnvironmentVariable("P4HOST", ""); return serverValid; } /// <summary> /// Checks that the user password if valid /// </summary> /// <returns></returns> public static bool CheckUsernamePassword() { // Connect to the server with the username Server testServer = new Server(new ServerAddress(Config.ServerURI)); Repository depot = new Repository(testServer); Connection con = depot.Connection; if (Config.OverrideHostname) { System.Environment.SetEnvironmentVariable("P4HOST", Config.Hostname); } if (Config.OverrideCharset) { System.Environment.SetEnvironmentVariable("P4CHARSET", Config.Charset); } con.UserName = Config.Username; bool passwordValid = false; try { // Attempt to open a secure connection with the given password con.Connect(null); con.Trust(new TrustCmdOptions(TrustCmdFlags.AutoAccept), ""); Credential credentials = con.Login(Config.Password); passwordValid = (credentials != null); con.Disconnect(); } catch (P4Exception) { passwordValid = false; } System.Environment.SetEnvironmentVariable("P4HOST", ""); System.Environment.SetEnvironmentVariable("P4CHARSET", ""); return passwordValid; } /// <summary> /// Check that the workspace is valid /// </summary> public static bool CheckWorkspace() { if (String.IsNullOrEmpty(Config.Workspace)) return false; // Open a connection, assume a secure one, won't hurt if it's not needed Server testServer = new Server(new ServerAddress(Config.ServerURI)); Repository depot = new Repository(testServer); Connection con = depot.Connection; if (Config.OverrideHostname) { System.Environment.SetEnvironmentVariable("P4HOST", Config.Hostname); } if (Config.OverrideCharset) { System.Environment.SetEnvironmentVariable("P4CHARSET", Config.Charset); } con.UserName = Config.Username; bool workspaceValid = false; try { // Open the connection and try to get the list of opened files on the workspace con.Client = new Client(); con.Client.Name = Config.Workspace; con.Connect(null); con.Trust(new TrustCmdOptions(TrustCmdFlags.AutoAccept), ""); Credential credentials = con.Login(Config.Password); con.Credential = credentials; // Try to get the list of opened files, it'll throw an exception if workspace is invalid depot.GetOpenedFiles(null, null); con.Disconnect(); // made it all the way workspaceValid = true; } catch (P4Exception) { workspaceValid = false; } System.Environment.SetEnvironmentVariable("P4HOST", ""); System.Environment.SetEnvironmentVariable("P4CHARSET", ""); return workspaceValid; } /// <summary> /// Verifies that the project root is valid /// </summary> public static bool CheckProjectRoot() { // Open a connection, assume a secure one, won't hurt if it's not needed Server testServer = new Server(new ServerAddress(Config.ServerURI)); Repository depot = new Repository(testServer); Connection con = depot.Connection; if (Config.OverrideHostname) { System.Environment.SetEnvironmentVariable("P4HOST", Config.Hostname); } if (Config.OverrideCharset) { System.Environment.SetEnvironmentVariable("P4CHARSET", Config.Charset); } con.UserName = Config.Username; bool rootValid = false; try { // Open the connection and try to get the list of opened files on the workspace con.Client = new Client(); con.Client.Name = Config.Workspace; con.Connect(null); con.Trust(new TrustCmdOptions(TrustCmdFlags.AutoAccept), ""); Credential credentials = con.Login(Config.Password); con.Credential = credentials; ClientMetadata metaData = depot.GetClientMetadata(); if (metaData != null) { LastWorkspaceMapping = metaData.Root.Replace('/', System.IO.Path.DirectorySeparatorChar); rootValid = Utils.IsDirOrValidSubDirectoryOf(Main.RootPath, LastWorkspaceMapping); } con.Disconnect(); } catch (P4Exception ex) { Debug.LogException(ex); rootValid = false; } System.Environment.SetEnvironmentVariable("P4HOST", ""); System.Environment.SetEnvironmentVariable("P4CHARSET", ""); return rootValid; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#9 | 16210 | Norman Morse | Remove files from old locations | ||
#8 | 15244 | Norman Morse |
Better Directory support in "add" "get latest" "refresh" and other commands. Improved Project Root detection Various Bug Fixes and Clean up |
||
#7 | 12568 | Norman Morse | Fixed some error handling during Perforce Configuration | ||
#6 | 12565 | Norman Morse |
Integrated from Dev Branch Made ChangeManager into Static Class. Improved close window behavior for when connection is invalid Fixed localOpenFiles not updating on submit |
||
#5 | 12553 | Norman Morse |
integrate from internal main Build fixes for EC. Major changes to Configuration and re-initialization code. Bug fixes |
||
#4 | 12512 | Norman Morse | Integrate from Dev branch, preparing for Beta3 release | ||
#3 | 12251 | Norman Morse |
Fixes for Beta 2 release Mostly Configuration dialog bug fixes |
||
#2 | 12135 | Norman Morse |
Integrate dev branch changes into main. This code is the basiis of the 2.7 BETA release which provides Unity 5 compatibility |
||
#1 | 10940 | Norman Morse |
Inital Workshop release of P4Connect. Released under BSD-2 license |