-
-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contents: start to add content manager support
- Loading branch information
1 parent
681b1ff
commit 207989d
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/winlator/contents/ContentProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.winlator.contents; | ||
|
||
import java.util.List; | ||
|
||
public class ContentProfile { | ||
public static final String CONTENT_TYPE_WINE = "WINE"; | ||
public static final String CONTENT_TYPE_TURNIP = "TURNIP"; | ||
public static final String CONTENT_TYPE_VIRGL = "VIRGL"; | ||
public static final String CONTENT_TYPE_DXVK = "DXVK"; | ||
public static final String CONTENT_TYPE_VKD3D = "VKD3D"; | ||
|
||
public String type; | ||
public String verName; | ||
public int verCode; | ||
public String desc; | ||
public List<String> fileList; | ||
} |
103 changes: 103 additions & 0 deletions
103
app/src/main/java/com/winlator/contents/ContentsManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.winlator.contents; | ||
|
||
import android.content.Context; | ||
import android.net.Uri; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.winlator.core.FileUtils; | ||
import com.winlator.core.TarCompressorUtils; | ||
|
||
import org.json.JSONObject; | ||
|
||
import java.io.File; | ||
|
||
public class ContentsManager { | ||
public enum InstallFailedReason { | ||
ERROR_NOSPACE, | ||
ERROR_BADTAR, | ||
ERROR_NOPROFILE, | ||
ERROR_BADPROFILE, | ||
ERROR_MISSINGFILES, | ||
ERROR_UNKNOWN | ||
} | ||
|
||
public enum ContentDirName { | ||
CONTENT_MAIN_DIR_NAME("contents"), | ||
CONTENT_WINE_DIR_NAME("wine"), | ||
CONTENT_TURNIP_DIR_NAME("turnip"), | ||
CONTENT_VIRGL_DIR_NAME("virgl"), | ||
CONTENT_DXVK_DIR_NAME("dxvk"), | ||
CONTENT_VKD3D_DIR_NAME("vkd3d"); | ||
|
||
private String name; | ||
|
||
ContentDirName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
} | ||
|
||
private Context context; | ||
|
||
public ContentsManager(Context context) { | ||
this.context = context; | ||
} | ||
|
||
public interface OnInstallFinishedCallback { | ||
void onFailed(InstallFailedReason reason, Exception e); | ||
|
||
void onSucceed(ContentProfile profile); | ||
} | ||
|
||
public void syncContents(boolean clean) { | ||
// 创建Profile列表 | ||
// 按类型搜索目录 | ||
// 找到目录后判断是否包含profile | ||
// 若不包含则直接删除目录 | ||
// 若包含在尝试读取 | ||
// 读取失败直接删除目录 | ||
// 读取后验证文件列表 | ||
// 验证失败直接删除目录 | ||
// 全部成功则放入Profile列表 | ||
} | ||
|
||
public void installContentFile(Uri uri, OnInstallFinishedCallback callback) { | ||
// 清理临时文件夹 | ||
// 创建临时文件夹 | ||
File file = new File(context.getFilesDir(), "tmp/" + ContentDirName.CONTENT_MAIN_DIR_NAME); | ||
FileUtils.delete(file); | ||
file.mkdirs(); | ||
// 尝试解压文件 | ||
// 若失败则回调 | ||
boolean ret; | ||
ret = TarCompressorUtils.extract(TarCompressorUtils.Type.XZ, context, uri, file); | ||
if (!ret) | ||
ret = TarCompressorUtils.extract(TarCompressorUtils.Type.ZSTD, context, uri, file); | ||
if (!ret) { | ||
callback.onFailed(InstallFailedReason.ERROR_BADTAR, null); | ||
return; | ||
} | ||
// 成功则尝试读取 Profile | ||
// 失败则回调 | ||
// 尝试验证 Profile | ||
// 失败则回调 | ||
// 将解压的文件移动到指定位置 | ||
// 执行成功回调 | ||
} | ||
|
||
public ContentProfile loadProfile(File file) { | ||
// TODO: | ||
try { | ||
JSONObject profileJSONObject = new JSONObject(FileUtils.readString(file)); | ||
} catch (Exception e) { | ||
|
||
} | ||
return null; | ||
} | ||
} |