Exemple #1
0
 public static void DisposeCurrent()
 {
     lock (ClientLock)
     {
         // If virtual client is initialized then...
         if (Current != null)
         {
             Current.Dispose();
         }
         return;
     }
 }
 /// <summary>
 /// Check ViGEm client. Create if not exists.
 /// </summary>
 /// <returns></returns>
 public static bool isVBusExists(bool createIfMissing = false)
 {
     lock (ClientLock)
     {
         // If Visual Studio C++ 2015 Redistributable installation unknown then...
         if (!RuntimeInstalled.HasValue)
         {
             var issue = Environment.Is64BitProcess
                 ? (IssueItem) new CppX64RuntimeInstallIssue()
                 : (IssueItem) new CppX86RuntimeInstallIssue();
             issue.Check();
             RuntimeInstalled = issue.Severity == IssueSeverity.None;
         }
         if (!RuntimeInstalled.Value)
         {
             return(false);
         }
         // Keep error for 5 seconds.
         if (DateTime.Now.Subtract(PendingErrorTime).TotalSeconds > 5)
         {
             PendingError = null;
         }
         // Do not process until user dealt with the error.
         if (PendingError.HasValue)
         {
             return(PendingError.Value == VIGEM_ERROR.VIGEM_ERROR_NONE);
         }
         // If client exists and it was not disposed then...
         if (Current != null && !Current.Disposing && !Current.IsDisposed)
         {
             return(true);
         }
         VIGEM_ERROR error;
         if (!IsLoaded)
         {
             LoadLibrary();
         }
         var client = new ViGEmClient(out error);
         if (error == VIGEM_ERROR.VIGEM_ERROR_NONE)
         {
             PendingError = null;
             Current      = client;
         }
         else
         {
             PendingError     = error;
             PendingErrorTime = DateTime.Now;
             client.Dispose();
             FreeLibrary();
         }
         return(error == VIGEM_ERROR.VIGEM_ERROR_NONE);
     }
 }