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 | |
---|---|---|---|---|---|
#14 | 16251 | Norman Morse | Update Dev branch to match reorganization in workshop | ||
#13 | 12863 | Norman Morse |
import from main Recently updated from internal Several Bugfixes logging clean up |
||
#12 | 12564 | Norman Morse |
Made ChangeManager into Static Class. Improved close window behavior for when connection is invalid Fixed localOpenFiles not updating on submit |
||
#11 | 12558 | Norman Morse | Integrate from main to dev | ||
#10 | 12510 | Norman Morse |
Another pass at the Configuration UI. password now works but is not obscured in the registry. Fixed browse buttons to use previous paths if set. Removed obsolete fields Removed debugging |
||
#9 | 12467 | Norman Morse |
Many minor changes to improve logging Added a filter for Console log display where you can select a level Hooked the log file location to the Configuration Log Entry. |
||
#8 | 12363 | Norman Morse |
Merging //guest/perforce_software/p4connect/src/... to //guest/norman_morse/dev/p4connect/src/... |
||
#7 | 12244 | Norman Morse |
Fixes to Configuration GUI. Fixes to ProgramName and ProgramVer being passed to Connection. |
||
#6 | 12099 | Norman Morse |
Various changes to prepare for Beta Fixed VersionInfo to show changeID Added "additional ignore in config". Updated ReleaseNotes |
||
#5 | 11841 | Norman Morse | Multi-platform build for unity 4.x fixup changes | ||
#4 | 11821 | Norman Morse | Move Unity 5 compatible build from internal dev branch to workshop dev branch. | ||
#3 | 11172 | Norman Morse | P4Config integration. | ||
#2 | 11092 | Norman Morse | Build Changes, some work on improving connections | ||
#1 | 10941 | Norman Morse | Create dev branch from workshop | ||
//guest/perforce_software/p4connect/src/P4Connect/P4Connect/P4Connect.VerifySettings.cs | |||||
#1 | 10940 | Norman Morse |
Inital Workshop release of P4Connect. Released under BSD-2 license |