hch
2024-03-26 9b086f7fa51af4d581ea9ef3638c97f4804fb60d
0312 白包
5个文件已修改
409 ■■■■■ 已修改文件
Channel/Android/test/debug/libs/library-debug-test.aar 补丁 | 查看 | 原始文档 | blame | 历史
Channel/Android/test/release/libs/library-release-test.aar 补丁 | 查看 | 原始文档 | blame | 历史
SdkProject/channel/test/java/com/secondworld/sdk/TestPlatform.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SdkProject/library/src/main/java/com/secondworld/sdk/command/CmdCopyAsset.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SdkProject/library/src/main/java/com/secondworld/sdk/utils/FileUtil.java 304 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Channel/Android/test/debug/libs/library-debug-test.aar
Binary files differ
Channel/Android/test/release/libs/library-release-test.aar
Binary files differ
SdkProject/channel/test/java/com/secondworld/sdk/TestPlatform.java
@@ -1,8 +1,57 @@
package com.secondworld.sdk;
public class TestPlatform extends PlatformDiff{
import android.content.Context;
public class TestPlatform extends PlatformDiff {
    @Override
    public String platformName() {
        return "test";
        return null;
    }
    @Override
    public String platformProductCode() {
        return null;
    }
    @Override
    public String platformProductKey() {
        return null;
    }
    @Override
    public void CreateRoleEvent(String roleID) {
    }
    @Override
    public void PayEvent(String title, String goodsID, double mount) {
    }
    @Override
    public void PrePayEvent(String title, String goodsID, double mount) {
    }
    @Override
    public void OnCreate(Context var0) {
    }
    @Override
    public String[] platformPermission() {
        return new String[0];
    }
    @Override
    public void LoginSuccess() {
    }
    @Override
    public void StartRequestPermission() {
    }
}
SdkProject/library/src/main/java/com/secondworld/sdk/command/CmdCopyAsset.java
@@ -1,19 +1,33 @@
package com.secondworld.sdk.command;
import com.secondworld.sdk.AsyncTaskOperator;
import com.secondworld.sdk.utils.CodeU2A;
import com.secondworld.sdk.utils.FileUtil;
import org.json.JSONObject;
public class CmdCopyAsset implements ICommand {
    @Override
    public int getCode() {
        return CodeU2A.CopyAsset;
    }
    @Override
    public void process(JSONObject json) {
        AsyncTaskOperator.I.run(FileUtil::copyAssets);
    }
}
package com.secondworld.sdk.command;
import com.secondworld.sdk.AsyncTaskOperator;
import com.secondworld.sdk.utils.CodeU2A;
import com.secondworld.sdk.utils.FileUtil;
import com.secondworld.sdk.utils.LogUtil;
import org.json.JSONObject;
public class CmdCopyAsset implements ICommand {
    @Override
    public int getCode() {
        return CodeU2A.CopyAsset;
    }
    @Override
    public void process(JSONObject json) {
        int copyType = 0;
        try {
            copyType = json.getInt("copyType");
        } catch (Exception e) {
            LogUtil.e("CmdCopyAsset", e);
        }
        if (copyType == 0)
        {
            AsyncTaskOperator.I.run(FileUtil::copyAssets);
        }
        else
        {
            AsyncTaskOperator.I.run(FileUtil::copyConfigs);
        }
    }
}
SdkProject/library/src/main/java/com/secondworld/sdk/utils/FileUtil.java
@@ -1,133 +1,171 @@
package com.secondworld.sdk.utils;
import android.content.res.AssetManager;
import com.secondworld.sdk.GameAppProxy;
import com.secondworld.sdk.UnityMsgHandler;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by Administrator on 2018/6/14 0014.
 */
public class FileUtil {
    /**
     * Unity随包资源批量拷贝
     */
    public static void copyAssets() {
        // 获取当前包的版本号
        final long currentVer = DeviceUtil.getVersionCode();
        // 已经拷贝过, 则再次判断一次版本号
        // 如果版本号不相同, 则重新进行拷贝
        // 获取本地存储的版本号
        long installVer = SPUtils.get().getLong(SPUtils.LAST_COPY_VERSION, 0);
        if (installVer == currentVer) {
            LogUtil.i("copyAssets", "已拷贝过,installVer:" + installVer + ";" + "currentVer:" + currentVer);
            UnityMsgHandler.sendMessageToUnity(CodeA2U.AssetCopyFinished);
            return;
        }
        String _dest = GameAppProxy.app.getExternalFilesDir("").getAbsolutePath();
        AssetManager _assetMgr = GameAppProxy.app.getAssets();
        try {
            String[] _fileNames = _assetMgr.list("android");
            if (_fileNames != null) {
                for (String _fileName : _fileNames) {
                    copy("android" + File.separator + _fileName,
                            _dest + File.separator + _fileName);
                }
            }
            LogUtil.i("copyAssets", "全部拷贝完成," + "currentVer:" + currentVer);
            // 存储此次的拷贝版本
            SPUtils.get().edit().putLong(SPUtils.LAST_COPY_VERSION, currentVer).apply();
            Map<String, Object> _msg = new HashMap<>();
            UnityMsgHandler.sendMessageToUnity(CodeA2U.AssetCopyFinished);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * unity单个资源拷贝
     *
     * @param fileName
     */
    public static void copyOneAsset(String fileName) {
        String originalPath = "android" + File.separator + fileName;
        String destPath = GameAppProxy.app.getExternalFilesDir(
                "").getAbsolutePath() + File.separator + fileName;
        String _destDir = destPath.substring(0, destPath.lastIndexOf('/') + 1);
        File _file = new File(_destDir);
        if (!_file.exists()) {
            boolean mkdir = _file.mkdir();
        }
        try {
            InputStream _is = GameAppProxy.app.getAssets().open(originalPath);
            FileOutputStream _fos = new FileOutputStream(new File(destPath));
            byte[] _buffer = new byte[1024];
            int _byteCount;
            while ((_byteCount = _is.read(_buffer)) != -1) {
                _fos.write(_buffer, 0, _byteCount);
            }
            _fos.flush();
            _is.close();
            _fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void copy(String original, String dest) {
        try {
            String[] fileNames = GameAppProxy.app.getAssets().list(original);
            if (fileNames.length > 0) {
                File dir = new File(dest);
                String mkdir = dir.mkdir() ? "成功" : "失败";
                LogUtil.i("copyAssets", "[" + original + "] 是一个文件夹, 创建文件夹: [" + dest + "] " + mkdir);
                for (String _fileName : fileNames) {
                    copy(original + File.separator + _fileName,
                            dest + File.separator + _fileName);
                }
            } else {
                InputStream _is = GameAppProxy.app.getAssets().open(original);
                FileOutputStream _fos = new FileOutputStream(new File(dest));
                byte[] _buffer = new byte[1024];
                int _byteCount;
                while ((_byteCount = _is.read(_buffer)) != -1) {
                    _fos.write(_buffer, 0, _byteCount);
                }
                _fos.flush();
                _is.close();
                _fos.close();
                LogUtil.i("copyAssets", "文件: " + original + " 已拷贝至: " + dest);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static String getFileNameWithoutExtension(String fileName) {
        return fileName.substring(0, fileName.lastIndexOf("."));
    }
    /**
     * 获取文件后缀名
     */
    public static String getSuffixName(File file) {
        String fileName = file.getName();
        int index = fileName.lastIndexOf(".");
        if (index == -1)
            return "";
        return fileName.substring(index + 1);
    }
}
package com.secondworld.sdk.utils;
import android.content.res.AssetManager;
import com.secondworld.sdk.GameAppProxy;
import com.secondworld.sdk.UnityMsgHandler;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by Administrator on 2018/6/14 0014.
 */
public class FileUtil {
    /**
     * Unity随包资源批量拷贝
     */
    public static void copyAssets() {
        // 获取当前包的版本号
        final long currentVer = DeviceUtil.getVersionCode();
        // 已经拷贝过, 则再次判断一次版本号
        // 如果版本号不相同, 则重新进行拷贝
        // 获取本地存储的版本号
        long installVer = SPUtils.get().getLong(SPUtils.LAST_COPY_VERSION, 0);
        if (installVer == currentVer) {
            LogUtil.i("copyAssets", "已拷贝过,installVer:" + installVer + ";" + "currentVer:" + currentVer);
            UnityMsgHandler.sendMessageToUnity(CodeA2U.AssetCopyFinished);
            return;
        }
        String _dest = GameAppProxy.app.getExternalFilesDir("").getAbsolutePath();
        AssetManager _assetMgr = GameAppProxy.app.getAssets();
        try {
            String[] _fileNames = _assetMgr.list("android");
            if (_fileNames != null) {
                for (String _fileName : _fileNames) {
                    copy("android" + File.separator + _fileName,
                            _dest + File.separator + _fileName);
                }
            }
            LogUtil.i("copyAssets", "全部拷贝完成," + "currentVer:" + currentVer);
            // 存储此次的拷贝版本
            SPUtils.get().edit().putLong(SPUtils.LAST_COPY_VERSION, currentVer).apply();
            Map<String, Object> _msg = new HashMap<>();
            UnityMsgHandler.sendMessageToUnity(CodeA2U.AssetCopyFinished);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void copyConfigs() {
        // 获取当前包的版本号
        final long currentVer = DeviceUtil.getVersionCode();
        // 已经拷贝过, 则再次判断一次版本号
        // 如果版本号不相同, 则重新进行拷贝
        // 获取本地存储的版本号
        long installVer = SPUtils.get().getLong("configsversion", 0);
        if (installVer == currentVer) {
            LogUtil.i("copyAssets", "已拷贝过,installVer:" + installVer + ";" + "currentVer:" + currentVer);
            UnityMsgHandler.sendMessageToUnity(CodeA2U.AssetCopyFinished);
            return;
        }
        String _dest = GameAppProxy.app.getExternalFilesDir("").getAbsolutePath();
        AssetManager _assetMgr = GameAppProxy.app.getAssets();
        try {
            String[] _fileNames = _assetMgr.list("android/config");
            if (_fileNames != null) {
                for (String _fileName : _fileNames) {
                    copy("android/config" + File.separator + _fileName,
                            _dest + File.separator + _fileName);
                }
            }
            LogUtil.i("copyAssets", "全部拷贝完成," + "currentVer:" + currentVer);
            // 存储此次的拷贝版本
            SPUtils.get().edit().putLong("configsversion", currentVer).apply();
            Map<String, Object> _msg = new HashMap<>();
            UnityMsgHandler.sendMessageToUnity(CodeA2U.AssetCopyFinished);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * unity单个资源拷贝
     *
     * @param fileName
     */
    public static void copyOneAsset(String fileName) {
        String originalPath = "android" + File.separator + fileName;
        String destPath = GameAppProxy.app.getExternalFilesDir(
                "").getAbsolutePath() + File.separator + fileName;
        String _destDir = destPath.substring(0, destPath.lastIndexOf('/') + 1);
        File _file = new File(_destDir);
        if (!_file.exists()) {
            boolean mkdir = _file.mkdir();
        }
        try {
            InputStream _is = GameAppProxy.app.getAssets().open(originalPath);
            FileOutputStream _fos = new FileOutputStream(new File(destPath));
            byte[] _buffer = new byte[1024];
            int _byteCount;
            while ((_byteCount = _is.read(_buffer)) != -1) {
                _fos.write(_buffer, 0, _byteCount);
            }
            _fos.flush();
            _is.close();
            _fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void copy(String original, String dest) {
        try {
            String[] fileNames = GameAppProxy.app.getAssets().list(original);
            if (fileNames.length > 0) {
                File dir = new File(dest);
                String mkdir = dir.mkdir() ? "成功" : "失败";
                LogUtil.i("copyAssets", "[" + original + "] 是一个文件夹, 创建文件夹: [" + dest + "] " + mkdir);
                for (String _fileName : fileNames) {
                    copy(original + File.separator + _fileName,
                            dest + File.separator + _fileName);
                }
            } else {
                InputStream _is = GameAppProxy.app.getAssets().open(original);
                FileOutputStream _fos = new FileOutputStream(new File(dest));
                byte[] _buffer = new byte[1024];
                int _byteCount;
                while ((_byteCount = _is.read(_buffer)) != -1) {
                    _fos.write(_buffer, 0, _byteCount);
                }
                _fos.flush();
                _is.close();
                _fos.close();
                LogUtil.i("copyAssets", "文件: " + original + " 已拷贝至: " + dest);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static String getFileNameWithoutExtension(String fileName) {
        return fileName.substring(0, fileName.lastIndexOf("."));
    }
    /**
     * 获取文件后缀名
     */
    public static String getSuffixName(File file) {
        String fileName = file.getName();
        int index = fileName.lastIndexOf(".");
        if (index == -1)
            return "";
        return fileName.substring(index + 1);
    }
}