﻿using Toast.SmartDownloader;
using UnityEngine;

// Workaround crash when exit a standalone program in Windows 7
public partial class SmartDlExample
{
    private bool _okExit = false;

    public void OnClickExitOk()
    {
        _okExit = true;
        Application.Quit();
    }

    public void OnClickExitCancel()
    {
        _okExit = false;
        ExitPanel.gameObject.SetActive(false);

        if (_recentResultCode == ResultCode.Cancel)
            OnClickStartDownload();
    }

    private void OnApplicationQuit()
    {
        if (Application.isEditor)
            return;

        if (Application.platform != RuntimePlatform.WindowsPlayer)
            return;

        if (!_okExit)
            Application.CancelQuit();

        if (!ExitPanel.gameObject.activeSelf)
        {
            SmartDl.StopDownload();

            ExitPanel.gameObject.SetActive(true);
            Application.CancelQuit();
        }
    }
}
