| | |
| | | |
| | | import android.content.res.AssetManager; |
| | | |
| | | import com.secondworld.sdk.GameApp; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | import com.secondworld.sdk.UnityMsgHandler; |
| | | |
| | | import java.io.File; |
| | |
| | | return; |
| | | } |
| | | |
| | | String _dest = GameApp.I.getExternalFilesDir("").getAbsolutePath(); |
| | | AssetManager _assetMgr = GameApp.I.getAssets(); |
| | | String _dest = GameAppProxy.app.getExternalFilesDir("").getAbsolutePath(); |
| | | AssetManager _assetMgr = GameAppProxy.app.getAssets(); |
| | | try { |
| | | String[] _fileNames = _assetMgr.list("android"); |
| | | if (_fileNames != null) { |
| | |
| | | } |
| | | } |
| | | |
| | | public static void copyConfigs() { |
| | | |
| | | // 获取当前包的版本号 |
| | | final long currentVer = DeviceUtil.getVersionCode(); |
| | | |
| | | // 已经拷贝过, 则再次判断一次版本号 |
| | | // 如果版本号不相同, 则重新进行拷贝 |
| | | |
| | | // 获取本地存储的版本号 |
| | | long installVer = SPUtils.get().getLong("configsversion", 0); |
| | | |
| | | if (installVer == currentVer) { |
| | | LogUtil.i("copyConfigs", "已拷贝过,installVer:" + installVer + ";" + "currentVer:" + currentVer); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.AssetCopyFinished); |
| | | return; |
| | | } |
| | | |
| | | String _dest = GameAppProxy.app.getExternalFilesDir("").getAbsolutePath() + File.separator + "config"; |
| | | File _file = new File(_dest); |
| | | if (!_file.exists()) { |
| | | boolean mkdir = _file.mkdir(); |
| | | } |
| | | 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("copyConfigs", "全部拷贝完成," + "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单个资源拷贝 |
| | | * |
| | |
| | | */ |
| | | public static void copyOneAsset(String fileName) { |
| | | String originalPath = "android" + File.separator + fileName; |
| | | String destPath = GameApp.I.getExternalFilesDir( |
| | | String destPath = GameAppProxy.app.getExternalFilesDir( |
| | | "").getAbsolutePath() + File.separator + fileName; |
| | | String _destDir = destPath.substring(0, destPath.lastIndexOf('/') + 1); |
| | | File _file = new File(_destDir); |
| | |
| | | boolean mkdir = _file.mkdir(); |
| | | } |
| | | try { |
| | | InputStream _is = GameApp.I.getAssets().open(originalPath); |
| | | InputStream _is = GameAppProxy.app.getAssets().open(originalPath); |
| | | FileOutputStream _fos = new FileOutputStream(new File(destPath)); |
| | | byte[] _buffer = new byte[1024]; |
| | | int _byteCount; |
| | |
| | | |
| | | public static void copy(String original, String dest) { |
| | | try { |
| | | String[] fileNames = GameApp.I.getAssets().list(original); |
| | | String[] fileNames = GameAppProxy.app.getAssets().list(original); |
| | | if (fileNames.length > 0) { |
| | | File dir = new File(dest); |
| | | String mkdir = dir.mkdir() ? "成功" : "失败"; |
| | |
| | | dest + File.separator + _fileName); |
| | | } |
| | | } else { |
| | | InputStream _is = GameApp.I.getAssets().open(original); |
| | | InputStream _is = GameAppProxy.app.getAssets().open(original); |
| | | FileOutputStream _fos = new FileOutputStream(new File(dest)); |
| | | byte[] _buffer = new byte[1024]; |
| | | int _byteCount; |