output logs.
This commit is contained in:
@@ -27,3 +27,4 @@ sysinfo.txt
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
/Assets/AssetStoreTools*
|
/Assets/AssetStoreTools*
|
||||||
/Assets/Extensions*
|
/Assets/Extensions*
|
||||||
|
/uDesktopDuplication.log
|
||||||
|
|||||||
Binary file not shown.
@@ -39,9 +39,17 @@ public enum MonitorState
|
|||||||
AccessLost = 6,
|
AccessLost = 6,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum DebugMode
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
File = 1,
|
||||||
|
UnityLog = 2, /* currently has bug when app exits. */
|
||||||
|
}
|
||||||
|
|
||||||
public static class Lib
|
public static class Lib
|
||||||
{
|
{
|
||||||
public delegate void MessageHandler(Message message);
|
public delegate void MessageHandler(Message message);
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
public delegate void DebugLogDelegate(string str);
|
public delegate void DebugLogDelegate(string str);
|
||||||
|
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
@@ -59,9 +67,11 @@ public static class Lib
|
|||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern void DisableDebug();
|
public static extern void DisableDebug();
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern void SetLogFunc(DebugLogDelegate func);
|
public static extern void SetDebugMode(DebugMode mode);
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern void SetErrorFunc(DebugLogDelegate func);
|
public static extern void SetLogFunc(IntPtr func);
|
||||||
|
[DllImport("uDesktopDuplication")]
|
||||||
|
public static extern void SetErrorFunc(IntPtr func);
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern int GetMonitorCount();
|
public static extern int GetMonitorCount();
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace uDesktopDuplication
|
namespace uDesktopDuplication
|
||||||
{
|
{
|
||||||
@@ -51,21 +52,20 @@ public class Manager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SerializeField] DebugMode debugMode = DebugMode.File;
|
||||||
[SerializeField] int desktopDuplicationApiTimeout = 0;
|
[SerializeField] int desktopDuplicationApiTimeout = 0;
|
||||||
[SerializeField] float retryReinitializationDuration = 1f;
|
[SerializeField] float retryReinitializationDuration = 1f;
|
||||||
|
|
||||||
private Coroutine renderCoroutine_ = null;
|
private Coroutine renderCoroutine_ = null;
|
||||||
private bool shouldReinitialize = false;
|
private bool shouldReinitialize_ = false;
|
||||||
private float reinitializationTimer = 0f;
|
private float reinitializationTimer_ = 0f;
|
||||||
|
|
||||||
public delegate void ReinitializeHandler();
|
public delegate void ReinitializeHandler();
|
||||||
public static event ReinitializeHandler onReinitialized;
|
public static event ReinitializeHandler onReinitialized;
|
||||||
|
|
||||||
private Lib.DebugLogDelegate logFunc = msg => Debug.Log(msg);
|
|
||||||
private Lib.DebugLogDelegate errorFunc = msg => Debug.LogError(msg);
|
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
|
Lib.SetDebugMode(debugMode);
|
||||||
Lib.InitializeUDD();
|
Lib.InitializeUDD();
|
||||||
|
|
||||||
if (instance_ != null) return;
|
if (instance_ != null) return;
|
||||||
@@ -84,16 +84,10 @@ public class Manager : MonoBehaviour
|
|||||||
void OnEnable()
|
void OnEnable()
|
||||||
{
|
{
|
||||||
renderCoroutine_ = StartCoroutine(OnRender());
|
renderCoroutine_ = StartCoroutine(OnRender());
|
||||||
|
|
||||||
Lib.SetLogFunc(logFunc);
|
|
||||||
Lib.SetErrorFunc(errorFunc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDisable()
|
void OnDisable()
|
||||||
{
|
{
|
||||||
Lib.SetLogFunc(null);
|
|
||||||
Lib.SetErrorFunc(null);
|
|
||||||
|
|
||||||
if (renderCoroutine_ != null) {
|
if (renderCoroutine_ != null) {
|
||||||
StopCoroutine(renderCoroutine_);
|
StopCoroutine(renderCoroutine_);
|
||||||
renderCoroutine_ = null;
|
renderCoroutine_ = null;
|
||||||
@@ -123,20 +117,20 @@ public class Manager : MonoBehaviour
|
|||||||
monitor.state == MonitorState.AccessLost ||
|
monitor.state == MonitorState.AccessLost ||
|
||||||
monitor.state == MonitorState.AccessDenied ||
|
monitor.state == MonitorState.AccessDenied ||
|
||||||
monitor.state == MonitorState.SessionDisconnected) {
|
monitor.state == MonitorState.SessionDisconnected) {
|
||||||
if (!shouldReinitialize) {
|
if (!shouldReinitialize_) {
|
||||||
shouldReinitialize = true;
|
shouldReinitialize_ = true;
|
||||||
reinitializationTimer = 0f;
|
reinitializationTimer_ = 0f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldReinitialize) {
|
if (shouldReinitialize_) {
|
||||||
if (reinitializationTimer > retryReinitializationDuration) {
|
if (reinitializationTimer_ > retryReinitializationDuration) {
|
||||||
Reinitialize();
|
Reinitialize();
|
||||||
shouldReinitialize = false;
|
shouldReinitialize_ = false;
|
||||||
}
|
}
|
||||||
reinitializationTimer += Time.deltaTime;
|
reinitializationTimer_ += Time.deltaTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,10 +136,6 @@ void Cursor::UpdateTexture()
|
|||||||
rowMax = h;
|
rowMax = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[256];
|
|
||||||
sprintf_s(buf, 256, "%d %d %d %d | %d %d %d %d", x_, y_, w, h, colMin, colMax, rowMin, rowMax);
|
|
||||||
Debug::Log(buf);
|
|
||||||
|
|
||||||
D3D11_TEXTURE2D_DESC desc;
|
D3D11_TEXTURE2D_DESC desc;
|
||||||
desc.Width = w;
|
desc.Width = w;
|
||||||
desc.Height = h;
|
desc.Height = h;
|
||||||
|
|||||||
@@ -4,28 +4,81 @@
|
|||||||
#include "Debug.h"
|
#include "Debug.h"
|
||||||
|
|
||||||
|
|
||||||
#define INIT_STATIC_MEMBER(Member, Value) \
|
decltype(Debug::mode_) Debug::mode_ = Debug::Mode::kFile;
|
||||||
decltype(Debug::Member) Debug::Member = Value;
|
decltype(Debug::logFunc_) Debug::logFunc_ = nullptr;
|
||||||
INIT_STATIC_MEMBER(enabled_, true)
|
decltype(Debug::errFunc_) Debug::errFunc_ = nullptr;
|
||||||
INIT_STATIC_MEMBER(logFunc_, nullptr)
|
decltype(Debug::fs_) Debug::fs_;
|
||||||
INIT_STATIC_MEMBER(errFunc_, nullptr)
|
|
||||||
|
|
||||||
|
void Debug::Initialize()
|
||||||
|
{
|
||||||
|
if (mode_ == Mode::kFile)
|
||||||
|
{
|
||||||
|
fs_.open("uDesktopDuplication.log");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Debug::Finalize()
|
||||||
|
{
|
||||||
|
fs_.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Debug::Log(const char* msg)
|
void Debug::Log(const char* msg)
|
||||||
{
|
{
|
||||||
if (!enabled_ || logFunc_ == nullptr) return;
|
switch (mode_)
|
||||||
|
{
|
||||||
char buf[256];
|
case Mode::kNone:
|
||||||
sprintf_s(buf, 256, "[uDD::Log] %s", msg);
|
{
|
||||||
logFunc_(buf);
|
break;
|
||||||
|
}
|
||||||
|
case Mode::kFile:
|
||||||
|
{
|
||||||
|
if (fs_.good())
|
||||||
|
{
|
||||||
|
fs_ << "[uDD::Log] " << msg << std::endl;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Mode::kUnityLog:
|
||||||
|
{
|
||||||
|
if (logFunc_ == nullptr)
|
||||||
|
{
|
||||||
|
char buf[256];
|
||||||
|
sprintf_s(buf, 256, "[uDD::Log] %s", msg);
|
||||||
|
logFunc_(buf);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Debug::Error(const char* msg)
|
void Debug::Error(const char* msg)
|
||||||
{
|
{
|
||||||
if (!enabled_ || errFunc_ == nullptr) return;
|
switch (mode_)
|
||||||
|
{
|
||||||
char buf[256];
|
case Mode::kNone:
|
||||||
sprintf_s(buf, 256, "[uDD::Err] %s", msg);
|
{
|
||||||
errFunc_(buf);
|
break;
|
||||||
|
}
|
||||||
|
case Mode::kFile:
|
||||||
|
{
|
||||||
|
if (fs_.good())
|
||||||
|
{
|
||||||
|
fs_ << "[uDD::Err] " << msg << std::endl;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Mode::kUnityLog:
|
||||||
|
{
|
||||||
|
if (logFunc_ == nullptr)
|
||||||
|
{
|
||||||
|
char buf[256];
|
||||||
|
sprintf_s(buf, 256, "[uDD::Err] %s", msg);
|
||||||
|
errFunc_(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,23 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <fstream>
|
||||||
|
#include "IUnityInterface.h"
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
class Debug
|
class Debug
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void Enable() { enabled_ = true; }
|
enum class Mode
|
||||||
static void Disable() { enabled_ = false; }
|
{
|
||||||
|
kNone = 0,
|
||||||
|
kFile = 1,
|
||||||
|
kUnityLog = 2,
|
||||||
|
};
|
||||||
|
|
||||||
using DebugLogFuncPtr = void(*)(const char*);
|
using DebugLogFuncPtr = void(UNITY_INTERFACE_API *)(const char*);
|
||||||
|
|
||||||
|
static void SetMode(Mode mode) { mode_ = mode; }
|
||||||
|
static void Initialize();
|
||||||
|
static void Finalize();
|
||||||
static void SetLogFunc(DebugLogFuncPtr func) { logFunc_ = func; }
|
static void SetLogFunc(DebugLogFuncPtr func) { logFunc_ = func; }
|
||||||
static void SetErrorFunc(DebugLogFuncPtr func) { errFunc_ = func; }
|
static void SetErrorFunc(DebugLogFuncPtr func) { errFunc_ = func; }
|
||||||
|
|
||||||
@@ -16,7 +26,8 @@ public:
|
|||||||
static void Error(const char* msg);
|
static void Error(const char* msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool enabled_;
|
static Mode mode_;
|
||||||
|
static std::ofstream fs_;
|
||||||
static DebugLogFuncPtr logFunc_;
|
static DebugLogFuncPtr logFunc_;
|
||||||
static DebugLogFuncPtr errFunc_;
|
static DebugLogFuncPtr errFunc_;
|
||||||
};
|
};
|
||||||
@@ -14,6 +14,11 @@ Monitor::Monitor(int id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Monitor::~Monitor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Monitor::Initialize(IDXGIOutput* output)
|
void Monitor::Initialize(IDXGIOutput* output)
|
||||||
{
|
{
|
||||||
output->GetDesc(&outputDesc_);
|
output->GetDesc(&outputDesc_);
|
||||||
@@ -37,33 +42,33 @@ void Monitor::Initialize(IDXGIOutput* output)
|
|||||||
break;
|
break;
|
||||||
case E_INVALIDARG:
|
case E_INVALIDARG:
|
||||||
state_ = State::InvalidArg;
|
state_ = State::InvalidArg;
|
||||||
|
Debug::Error("Monitor::Initialize() => Invalid arguments.");
|
||||||
break;
|
break;
|
||||||
case E_ACCESSDENIED:
|
case E_ACCESSDENIED:
|
||||||
// For example, when the user presses Ctrl + Alt + Delete and the screen
|
// For example, when the user presses Ctrl + Alt + Delete and the screen
|
||||||
// switches to admin screen, this error occurs.
|
// switches to admin screen, this error occurs.
|
||||||
state_ = State::AccessDenied;
|
state_ = State::AccessDenied;
|
||||||
|
Debug::Error("Monitor::Initialize() => Access denied.");
|
||||||
break;
|
break;
|
||||||
case DXGI_ERROR_UNSUPPORTED:
|
case DXGI_ERROR_UNSUPPORTED:
|
||||||
// If the display adapter on the computer is running under the Microsoft Hybrid system,
|
// If the display adapter on the computer is running under the Microsoft Hybrid system,
|
||||||
// this error occurs.
|
// this error occurs.
|
||||||
state_ = State::Unsupported;
|
state_ = State::Unsupported;
|
||||||
|
Debug::Error("Monitor::Initialize() => Unsupported display.");
|
||||||
break;
|
break;
|
||||||
case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE:
|
case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE:
|
||||||
// When other application use Desktop Duplication API, this error occurs.
|
// When other application use Desktop Duplication API, this error occurs.
|
||||||
state_ = State::CurrentlyNotAvailable;
|
state_ = State::CurrentlyNotAvailable;
|
||||||
|
Debug::Error("Monitor::Initialize() => Currently not available.");
|
||||||
break;
|
break;
|
||||||
case DXGI_ERROR_SESSION_DISCONNECTED:
|
case DXGI_ERROR_SESSION_DISCONNECTED:
|
||||||
state_ = State::SessionDisconnected;
|
state_ = State::SessionDisconnected;
|
||||||
|
Debug::Error("Monitor::Initialize() => Session disconnected.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Monitor::~Monitor()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Monitor::Render(UINT timeout)
|
void Monitor::Render(UINT timeout)
|
||||||
{
|
{
|
||||||
if (!deskDupl_) return;
|
if (!deskDupl_) return;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
IUnityInterfaces* g_unity = nullptr;
|
IUnityInterfaces* g_unity = nullptr;
|
||||||
std::unique_ptr<MonitorManager> g_manager;
|
std::unique_ptr<MonitorManager> g_manager;
|
||||||
std::unique_ptr<Debug> g_debug;
|
|
||||||
std::queue<Message> g_messages;
|
std::queue<Message> g_messages;
|
||||||
|
|
||||||
|
|
||||||
@@ -31,14 +30,20 @@ extern "C"
|
|||||||
if (g_unity && !g_manager)
|
if (g_unity && !g_manager)
|
||||||
{
|
{
|
||||||
g_manager = std::make_unique<MonitorManager>();
|
g_manager = std::make_unique<MonitorManager>();
|
||||||
g_debug = std::make_unique<Debug>();
|
Debug::Initialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API FinalizeUDD()
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API FinalizeUDD()
|
||||||
{
|
{
|
||||||
g_manager.reset();
|
g_manager.reset();
|
||||||
g_debug.reset();
|
|
||||||
|
std::queue<Message> empty;
|
||||||
|
g_messages.swap(empty);
|
||||||
|
|
||||||
|
Debug::SetLogFunc(nullptr);
|
||||||
|
Debug::SetErrorFunc(nullptr);
|
||||||
|
Debug::Finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
|
||||||
@@ -49,8 +54,8 @@ extern "C"
|
|||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginUnload()
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginUnload()
|
||||||
{
|
{
|
||||||
g_unity = nullptr;
|
|
||||||
FinalizeUDD();
|
FinalizeUDD();
|
||||||
|
g_unity = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UNITY_INTERFACE_API OnRenderEvent(int id)
|
void UNITY_INTERFACE_API OnRenderEvent(int id)
|
||||||
@@ -88,28 +93,19 @@ extern "C"
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API EnableDebug()
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetDebugMode(Debug::Mode mode)
|
||||||
{
|
{
|
||||||
if (!g_debug) return;
|
Debug::SetMode(mode);
|
||||||
g_debug->Enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API DisableDebug()
|
|
||||||
{
|
|
||||||
if (!g_debug) return;
|
|
||||||
g_debug->Disable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetLogFunc(Debug::DebugLogFuncPtr func)
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetLogFunc(Debug::DebugLogFuncPtr func)
|
||||||
{
|
{
|
||||||
if (!g_debug) return;
|
Debug::SetLogFunc(func);
|
||||||
g_debug->SetLogFunc(func);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetErrorFunc(Debug::DebugLogFuncPtr func)
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetErrorFunc(Debug::DebugLogFuncPtr func)
|
||||||
{
|
{
|
||||||
if (!g_debug) return;
|
Debug::SetErrorFunc(func);
|
||||||
g_debug->SetErrorFunc(func);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UNITY_INTERFACE_EXPORT size_t UNITY_INTERFACE_API GetMonitorCount()
|
UNITY_INTERFACE_EXPORT size_t UNITY_INTERFACE_API GetMonitorCount()
|
||||||
|
|||||||
Reference in New Issue
Block a user