<?php

use App\Services\FileService;

$zipFile = MICRO_SERVER . 'websocket/swasocket.zip';
$installed = file_exists(MICRO_SERVER . 'websocket/installed.bin');

if (file_exists($zipFile) && !$installed){
    //清空文件夹
    if (is_dir(base_path('swasocket'))){
        @FileService::rmdirs(base_path('swasocket'), true);
    }else{
        FileService::mkdirs(base_path('swasocket'));
    }

    //解压文件
    $zip = new \ZipArchive();
    $openRes = $zip->open($zipFile);
    if ($openRes === TRUE) {
        $zip->extractTo(base_path('swasocket'));
        $zip->close();
        //新增安装文件
        file_put_contents(MICRO_SERVER . 'websocket/installed.bin', TIMESTAMP);
    }else{
        $zip->close();
    }
}

$finish = true;
