主题
获取自更新进度 - SoftUpdateGetProgress
函数简介
获取当前进程内自更新进度快照(下载/准备阶段)。Updater 已拉起且宿主退出后,请改读 SoftUpdateGetLastStatus。
返回数据格式:
json
{
"Code": 1,
"Phase": "downloading",
"Percent": 45,
"BytesCurrent": 1000000,
"BytesTotal": 2000000,
"Message": "",
"IsFinished": false,
"IsFailed": false
}| 字段名 | 类型 | 说明 |
|---|---|---|
| Code | 整数 | 1 表示接口调用成功。 |
| Phase | 字符串 | idle / checking / downloading / verifying / extracting_updater / launching / done / failed。 |
| Percent | 整数 | 0–100。 |
| BytesCurrent | 整数 | 已下载字节数。 |
| BytesTotal | 整数 | 总字节数;未知时为 0。 |
| Message | 字符串 | 阶段说明。 |
| IsFinished | 布尔 | 是否已结束(成功或失败)。 |
| IsFailed | 布尔 | 是否失败。 |
接口名称
SoftUpdateGetProgressDLL调用
long SoftUpdateGetProgress();参数说明
无参数。
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
OlaSoftUpdateProgressReturn progress = ola.SoftUpdateGetProgress();
// progress.Percent / progress.Phase / progress.IsFinishedcsharp
using OLAPlug;
var ola = new OLAPlugServer();
OlaSoftUpdateProgressReturn progress = ola.SoftUpdateGetProgress();python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
json_result = ola.SoftUpdateGetProgress()
# Python SDK 返回 JSON 字符串,需自行解析java
import com.olaplug.OLAPlugServer;
import com.olaplug.model.OlaSoftUpdateProgressReturn;
OLAPlugServer ola = new OLAPlugServer();
OlaSoftUpdateProgressReturn progress = ola.SoftUpdateGetProgress();go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
progress := ola.SoftUpdateGetProgress()rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let progress = ola.soft_update_get_progress();cpp
var ola = com("OlaPlug.OlaSoft")
var progress = ola.SoftUpdateGetProgress()vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
Set progress = ola.SoftUpdateGetProgress()text
.局部变量 ola, OLAPlug
.局部变量 progress, OlaSoftUpdateProgressReturn
ola.创建 ()
progress = ola.SoftUpdateGetProgress()aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var json = ola.SoftUpdateGetProgress();
// Aardio SDK 返回 JSON 字符串,需自行解析text
变量 ola <类型 = OLAPlugServer>
变量 progress <类型 = OlaSoftUpdateProgressReturn>
ola = 新建 OLAPlugServer
progress = ola.SoftUpdateGetProgress()cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
OlaSoftUpdateProgressReturn progress = ola.SoftUpdateGetProgress();原生 DLL 调用
cpp
long ptr = SoftUpdateGetProgress();
if (ptr != 0) {
char buffer[2048] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long SoftUpdateGetProgress();
long ptr = SoftUpdateGetProgress();
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
string result = sb.ToString();
}python
from ctypes import CDLL, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ptr = ola.SoftUpdateGetProgress()
if ptr:
buf = create_string_buffer(2048)
ola.GetStringFromPtr(ptr, buf, 2048)
ola.FreeStringPtr(ptr)
result = buf.value.decode("utf-8")返回值
| 调用方式 | 返回值 | 说明 |
|---|---|---|
| SDK | OlaSoftUpdateProgressReturn | 结构化进度对象 |
| 原生 DLL | 非 0 | 成功,返回 JSON 字符串指针 |
| 原生 DLL | 0 | 失败 |
注意事项
| 项目 | 说明 |
|---|---|
| 作用域 | 仅反映当前进程内下载/准备阶段;宿主退出后请用 SoftUpdateGetLastStatus。 |
| UI | 默认可静默;需要进度条时由宿主轮询本接口自行绘制。 |
| 释放内存 | 原生返回指针需 FreeStringPtr。 |
