#pragma once
#include <string>
#include <thread>
#include <atomic>

class injector
{
public:
    static injector* Get();

    /// <summary>
    /// 在新线程中启动注入流程：
    /// 1. 将嵌入的 SkeetInjector.exe 写入临时目录
    /// 2. 执行注入器
    /// 3. 清理临时文件
    /// </summary>
    bool Launch();

    /// <summary>
    /// 注入线程是否仍在运行
    /// </summary>
    bool IsRunning() const;

    /// <summary>
    /// 注入是否已成功完成
    /// </summary>
    bool HasSucceeded() const;

    /// <summary>
    /// 等待注入线程结束（阻塞调用）
    /// </summary>
    void Wait();

private:
    injector() = default;
    ~injector();
    injector(const injector&) = delete;
    injector& operator=(const injector&) = delete;

    /// <summary>
    /// 注入线程入口：写文件 → 执行 → 等待完成 → 清理
    /// </summary>
    void InjectionThread();

    std::string WriteInjectorToTemp();
    bool RunInjector(const std::string& exePath);
    void CleanupTempFile(const std::string& exePath);

    std::thread m_thread;
    std::atomic<bool> m_running = false;
    std::atomic<bool> m_success = false;
};
