mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Rework solution structure to allow more types of library projects (#196)
* Rename avalonia & wpf samples * Rename rest of samples * fix sample readme * Fix compat util tests * rename / move all src projects * remove package lock files and move libC# again * Add rust lib and cargo workspace * Replace locksmith lib with new filelocksmith-rs library * Deprecated type * fix setup compile * Use thiserror for error handling * Rename some enums and formatting * Add missing SHA256 * wip c++ library * cpp wip * alphabetize readme * Try to get build working again * Fix some conditionally compiled bits * cross config should be in workspace root * Fix PathHelper for new rust target dir * Missed one old path to velopack.csproj * remove obsolete coverage code * testawareapp.exe no longer exists
This commit is contained in:
1951
samples/CSharpUnityMono/Assets/Scenes/SampleScene.unity
Normal file
1951
samples/CSharpUnityMono/Assets/Scenes/SampleScene.unity
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9fc0d4010bbf28b4594072e72b8655ab
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
116
samples/CSharpUnityMono/Assets/Scenes/UpdateSample.cs
Normal file
116
samples/CSharpUnityMono/Assets/Scenes/UpdateSample.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Velopack;
|
||||
using ILogger = UnityEngine.ILogger;
|
||||
|
||||
public class UpdateSample : MonoBehaviour
|
||||
{
|
||||
public Button checkForUpdatesButton;
|
||||
public Button downloadUpdatesButton;
|
||||
public Button applyUpdatesButton;
|
||||
public TMPro.TextMeshProUGUI infoText;
|
||||
public TMPro.TMP_InputField inputField;
|
||||
|
||||
private UpdateManager m_UpdateManager;
|
||||
public int downloadProgress;
|
||||
public UpdateInfo NewVersion;
|
||||
private void Start()
|
||||
{
|
||||
if (checkForUpdatesButton)
|
||||
{
|
||||
checkForUpdatesButton.onClick.AddListener(CheckUpdate);
|
||||
}
|
||||
|
||||
if (downloadUpdatesButton)
|
||||
{
|
||||
downloadUpdatesButton.onClick.AddListener(DownloadUpdate);
|
||||
}
|
||||
|
||||
if (applyUpdatesButton)
|
||||
{
|
||||
applyUpdatesButton.onClick.AddListener(ApplyUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
private async void CheckUpdate()
|
||||
{
|
||||
var logger = new UpdateLogger();
|
||||
logger.LogAction += (message) => infoText.text = message;
|
||||
m_UpdateManager = new UpdateManager(inputField.text,logger: logger);
|
||||
NewVersion = await m_UpdateManager.CheckForUpdatesAsync();
|
||||
}
|
||||
private async void DownloadUpdate()
|
||||
{
|
||||
if(NewVersion == null)
|
||||
{
|
||||
infoText.text = "No new version found";
|
||||
return;
|
||||
}
|
||||
checkForUpdatesButton.interactable = false;
|
||||
downloadUpdatesButton.interactable = false;
|
||||
applyUpdatesButton.interactable = false;
|
||||
|
||||
await m_UpdateManager.DownloadUpdatesAsync(NewVersion, i =>
|
||||
{
|
||||
downloadProgress = i;
|
||||
infoText.text = $"Downloading {i}%";
|
||||
}).ConfigureAwait(true);
|
||||
checkForUpdatesButton.interactable = true;
|
||||
downloadUpdatesButton.interactable = true;
|
||||
applyUpdatesButton.interactable = true;
|
||||
}
|
||||
private void ApplyUpdate()
|
||||
{
|
||||
if (NewVersion == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//do not use m_UpdateManager.ApplyUpdatesAndExit(NewVersion); here, it has Environment.Exit(0) which will cause the Unity freeze
|
||||
m_UpdateManager.WaitExitThenApplyUpdates(NewVersion);
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
private class UpdateLogger : Microsoft.Extensions.Logging.ILogger
|
||||
{
|
||||
public Action<string> LogAction;
|
||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
||||
{
|
||||
var message = formatter(state, exception);
|
||||
|
||||
switch(logLevel)
|
||||
{
|
||||
case LogLevel.Trace:
|
||||
case LogLevel.Debug:
|
||||
case LogLevel.Information:
|
||||
Debug.Log(message);
|
||||
break;
|
||||
case LogLevel.Warning:
|
||||
Debug.LogWarning(message);
|
||||
break;
|
||||
case LogLevel.Error:
|
||||
case LogLevel.Critical:
|
||||
Debug.LogError(message);
|
||||
break;
|
||||
case LogLevel.None:
|
||||
default:
|
||||
return;
|
||||
}
|
||||
LogAction?.Invoke(message);
|
||||
}
|
||||
|
||||
public bool IsEnabled(LogLevel logLevel)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public IDisposable BeginScope<TState>(TState state)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
samples/CSharpUnityMono/Assets/Scenes/UpdateSample.cs.meta
Normal file
11
samples/CSharpUnityMono/Assets/Scenes/UpdateSample.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 677f92ae3db5e58479e317c515cd43be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user