mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
Add update check for Windows that now restarts the launcher.
This commit is contained in:
parent
6f60ae2c02
commit
12191fe45c
@ -83,31 +83,5 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CopyScaledPixels( FastBitmap src, FastBitmap dst, Size scale,
|
|
||||||
Rectangle srcRect, Rectangle dstRect, byte rgbScale ) {
|
|
||||||
int srcWidth = srcRect.Width, dstWidth = dstRect.Width;
|
|
||||||
int srcHeight = srcRect.Height, dstHeight = dstRect.Height;
|
|
||||||
int srcX = srcRect.X, dstX = dstRect.X;
|
|
||||||
int srcY = srcRect.Y, dstY = dstRect.Y;
|
|
||||||
int scaleWidth = scale.Width, scaleHeight = scale.Height;
|
|
||||||
|
|
||||||
for( int yy = 0; yy < dstHeight; yy++ ) {
|
|
||||||
int scaledY = yy * srcHeight / scaleHeight;
|
|
||||||
int* srcRow = src.GetRowPtr( srcY + scaledY );
|
|
||||||
int* dstRow = dst.GetRowPtr( dstY + yy );
|
|
||||||
|
|
||||||
for( int xx = 0; xx < dstWidth; xx++ ) {
|
|
||||||
int scaledX = xx * srcWidth / scaleWidth;
|
|
||||||
int pixel = srcRow[srcX + scaledX];
|
|
||||||
|
|
||||||
int col = pixel & ~0xFFFFFF; // keep a but clear rgb
|
|
||||||
col |= ((pixel & 0xFF) * rgbScale / 255);
|
|
||||||
col |= (((pixel >> 8) & 0xFF) * rgbScale / 255) << 8;
|
|
||||||
col |= (((pixel >> 16) & 0xFF) * rgbScale / 255) << 16;
|
|
||||||
dstRow[dstX + xx] = col;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,12 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using ClassicalSharp;
|
using ClassicalSharp;
|
||||||
|
using ClassicalSharp.TexturePack;
|
||||||
|
|
||||||
namespace Launcher2 {
|
namespace Launcher2 {
|
||||||
|
|
||||||
|
// TODO: Download asynchronously
|
||||||
public sealed class UpdatesScreen : LauncherScreen {
|
public sealed class UpdatesScreen : LauncherScreen {
|
||||||
|
|
||||||
Font titleFont, infoFont;
|
Font titleFont, infoFont;
|
||||||
@ -35,7 +38,7 @@ namespace Launcher2 {
|
|||||||
lastStable = DateTime.Parse( checkTask.LatestStableDate,
|
lastStable = DateTime.Parse( checkTask.LatestStableDate,
|
||||||
null, DateTimeStyles.AssumeUniversal );
|
null, DateTimeStyles.AssumeUniversal );
|
||||||
lastDev = DateTime.Parse( checkTask.LatestDevDate,
|
lastDev = DateTime.Parse( checkTask.LatestDevDate,
|
||||||
null, DateTimeStyles.AssumeUniversal );
|
null, DateTimeStyles.AssumeUniversal );
|
||||||
|
|
||||||
validStable = Int32.Parse( checkTask.LatestStableSize ) > 50000;
|
validStable = Int32.Parse( checkTask.LatestStableSize ) > 50000;
|
||||||
validDev = Int32.Parse( checkTask.LatestDevSize ) > 50000;
|
validDev = Int32.Parse( checkTask.LatestDevSize ) > 50000;
|
||||||
@ -70,17 +73,14 @@ namespace Launcher2 {
|
|||||||
string latestStable = GetDateString( lastStable, validStable );
|
string latestStable = GetDateString( lastStable, validStable );
|
||||||
MakeLabelAt( latestStable, infoFont, Anchor.Centre, Anchor.Centre, 100, -80 );
|
MakeLabelAt( latestStable, infoFont, Anchor.Centre, Anchor.Centre, 100, -80 );
|
||||||
MakeButtonAt( "Update to stable", 180, 30, titleFont, Anchor.Centre, 0, -40,
|
MakeButtonAt( "Update to stable", 180, 30, titleFont, Anchor.Centre, 0, -40,
|
||||||
(x, y) => UpdateBuild( lastDev, validDev, "latest.Release.zip" ) );
|
(x, y) => UpdateBuild( lastStable, validStable, "latest.Release.zip" ) );
|
||||||
|
|
||||||
MakeLabelAt( "Latest OpenGL dev:", titleFont, Anchor.Centre, Anchor.Centre, -100, 0 );
|
MakeLabelAt( "Latest dev:", titleFont, Anchor.Centre, Anchor.Centre, -60, 40 );
|
||||||
string latestDev = GetDateString( lastDev, validDev );
|
string latestDev = GetDateString( lastDev, validDev );
|
||||||
MakeLabelAt( latestDev, infoFont, Anchor.Centre, Anchor.Centre, 100, 0 );
|
MakeLabelAt( latestDev, infoFont, Anchor.Centre, Anchor.Centre, 100, 40 );
|
||||||
MakeButtonAt( "Update to OpenGL dev", 240, 30, titleFont, Anchor.Centre, 0, 40,
|
MakeButtonAt( "Update to OpenGL dev", 240, 30, titleFont, Anchor.Centre, 0, 80,
|
||||||
(x, y) => UpdateBuild( lastDev, validDev, "latest.zip" ) );
|
(x, y) => UpdateBuild( lastDev, validDev, "latest.zip" ) );
|
||||||
|
MakeButtonAt( "Update to D3D9 dev", 240, 30, titleFont, Anchor.Centre, 0, 120,
|
||||||
MakeLabelAt( "Latest D3D9 dev:", titleFont, Anchor.Centre, Anchor.Centre, -85, 80 );
|
|
||||||
MakeLabelAt( latestDev, infoFont, Anchor.Centre, Anchor.Centre, 100, 80 );
|
|
||||||
MakeButtonAt( "Update to D3D9 dev", 230, 30, titleFont, Anchor.Centre, 0, 120,
|
|
||||||
(x, y) => UpdateBuild( lastDev, validDev, "latest.DirectX.zip" ) );
|
(x, y) => UpdateBuild( lastDev, validDev, "latest.DirectX.zip" ) );
|
||||||
|
|
||||||
MakeButtonAt( "Back", 80, 35, titleFont, Anchor.Centre,
|
MakeButtonAt( "Back", 80, 35, titleFont, Anchor.Centre,
|
||||||
@ -98,8 +98,36 @@ namespace Launcher2 {
|
|||||||
if( last == DateTime.MinValue || !valid ) return;
|
if( last == DateTime.MinValue || !valid ) return;
|
||||||
|
|
||||||
using( WebClient client = new WebClient() ) {
|
using( WebClient client = new WebClient() ) {
|
||||||
client.DownloadFile( UpdateCheckTask.UpdatesUri + dir, "update.zip" );
|
byte[] zipData = client.DownloadData( UpdateCheckTask.UpdatesUri + dir );
|
||||||
|
MakeUpdatesFolder( zipData );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( !OpenTK.Configuration.RunningOnWindows )
|
||||||
|
return; // TODO: bash script for OSX and linux
|
||||||
|
if( !File.Exists( "update.bat" ) )
|
||||||
|
File.WriteAllText( "update.bat", batch );
|
||||||
|
|
||||||
|
ProcessStartInfo info = new ProcessStartInfo( "cmd.exe", "/c update.bat" );
|
||||||
|
info.CreateNoWindow = false;
|
||||||
|
info.UseShellExecute = false;
|
||||||
|
Process p = Process.Start( info );
|
||||||
|
Process.GetCurrentProcess().Kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MakeUpdatesFolder( byte[] zipData ) {
|
||||||
|
using( MemoryStream stream = new MemoryStream( zipData ) ) {
|
||||||
|
ZipReader reader = new ZipReader();
|
||||||
|
Directory.CreateDirectory( "CS_Update" );
|
||||||
|
|
||||||
|
reader.ShouldProcessZipEntry = (f) => true;
|
||||||
|
reader.ProcessZipEntry = ProcessZipEntry;
|
||||||
|
reader.Extract( stream );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessZipEntry( string filename, byte[] data, ZipEntry entry ) {
|
||||||
|
string path = Path.Combine( "CS_Update", Path.GetFileName( filename ) );
|
||||||
|
File.WriteAllBytes( path, data );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
@ -109,5 +137,30 @@ namespace Launcher2 {
|
|||||||
titleFont.Dispose();
|
titleFont.Dispose();
|
||||||
infoFont.Dispose();
|
infoFont.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const string batch =
|
||||||
|
@"
|
||||||
|
@echo off
|
||||||
|
echo Waiting for launcher to exit..
|
||||||
|
echo 5..
|
||||||
|
sleep 1
|
||||||
|
echo 4..
|
||||||
|
sleep 1
|
||||||
|
echo 3..
|
||||||
|
sleep 1
|
||||||
|
echo 2..
|
||||||
|
sleep 1
|
||||||
|
echo 1..
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
set root=%CD%
|
||||||
|
echo Extracting files from CS_Update folder
|
||||||
|
|
||||||
|
for /f ""tokens=*"" %%f in ('dir /b ""%root%\CS_Update""') do move ""%root%\CS_Update\%%f"" ""%root%\%%f""
|
||||||
|
rmdir ""%root%\CS_Update""
|
||||||
|
|
||||||
|
echo Starting launcher again
|
||||||
|
start Launcher2.exe
|
||||||
|
exit";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<ProjectGuid>{3E84ACC1-27B4-401B-A359-6AAE4DF6C9B5}</ProjectGuid>
|
<ProjectGuid>{3E84ACC1-27B4-401B-A359-6AAE4DF6C9B5}</ProjectGuid>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<RootNamespace>Launcher2</RootNamespace>
|
<RootNamespace>Launcher2</RootNamespace>
|
||||||
<AssemblyName>Launcher2</AssemblyName>
|
<AssemblyName>Launcher2</AssemblyName>
|
||||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||||
|
@ -84,10 +84,36 @@ namespace Launcher2 {
|
|||||||
|
|
||||||
Size size = new Size( tileSize, tileSize );
|
Size size = new Size( tileSize, tileSize );
|
||||||
Rectangle dstRect = new Rectangle( x, y, x2 - x, y2 - y );
|
Rectangle dstRect = new Rectangle( x, y, x2 - x, y2 - y );
|
||||||
FastBitmap.CopyScaledPixels( dirtFastBmp, dst, size, srcRect, dstRect, 128 );
|
CopyScaledPixels( dirtFastBmp, dst, size, srcRect, dstRect, 128 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe static void CopyScaledPixels( FastBitmap src, FastBitmap dst, Size scale,
|
||||||
|
Rectangle srcRect, Rectangle dstRect, byte rgbScale ) {
|
||||||
|
int srcWidth = srcRect.Width, dstWidth = dstRect.Width;
|
||||||
|
int srcHeight = srcRect.Height, dstHeight = dstRect.Height;
|
||||||
|
int srcX = srcRect.X, dstX = dstRect.X;
|
||||||
|
int srcY = srcRect.Y, dstY = dstRect.Y;
|
||||||
|
int scaleWidth = scale.Width, scaleHeight = scale.Height;
|
||||||
|
|
||||||
|
for( int yy = 0; yy < dstHeight; yy++ ) {
|
||||||
|
int scaledY = yy * srcHeight / scaleHeight;
|
||||||
|
int* srcRow = src.GetRowPtr( srcY + scaledY );
|
||||||
|
int* dstRow = dst.GetRowPtr( dstY + yy );
|
||||||
|
|
||||||
|
for( int xx = 0; xx < dstWidth; xx++ ) {
|
||||||
|
int scaledX = xx * srcWidth / scaleWidth;
|
||||||
|
int pixel = srcRow[srcX + scaledX];
|
||||||
|
|
||||||
|
int col = pixel & ~0xFFFFFF; // keep a but clear rgb
|
||||||
|
col |= ((pixel & 0xFF) * rgbScale / 255);
|
||||||
|
col |= (((pixel >> 8) & 0xFF) * rgbScale / 255) << 8;
|
||||||
|
col |= (((pixel >> 16) & 0xFF) * rgbScale / 255) << 16;
|
||||||
|
dstRow[dstX + xx] = col;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user