/*
 * Auto-CreamAPI
 * Copyright (C) 2020 Jeddunk
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program. If not, see
 * <https://www.gnu.org/licenses/>.
 */

package xyz.jeddunk.autocreamapi.util;

import org.apache.commons.codec.digest.DigestUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class CreamApiDllHandler {

    private static CreamApiDllHandler creamApiDllHandlerInstance;
    private final Path steamApiDllPath = Paths.get("steam_api.dll");
    private final Path steamApi64DllPath = Paths.get("steam_api64.dll");
    private final String steamApiDllMd5;
    private final String steamApi64DllMd5;

    private CreamApiDllHandler() throws IOException {
        this.steamApiDllMd5 = DigestUtils.md5Hex(Files.newInputStream(steamApiDllPath));
        this.steamApi64DllMd5 = DigestUtils.md5Hex(Files.newInputStream(steamApi64DllPath));
    }

    public static synchronized CreamApiDllHandler getInstance() throws IOException {
        if (creamApiDllHandlerInstance == null) {
            creamApiDllHandlerInstance = new CreamApiDllHandler();
        }
        return creamApiDllHandlerInstance;
    }

    public Path getDllPath(boolean is64Bit) {
        return is64Bit ? steamApi64DllPath : steamApiDllPath;
    }

    public String getDllMd5(boolean is64Bit) {
        return is64Bit ? steamApi64DllMd5 : steamApiDllMd5;
    }
}
