238 lines
10 KiB
C#
238 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
//using System.Deployment.Application;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Interop;
|
|
using System.Runtime.InteropServices;
|
|
using System.Windows.Media;
|
|
using System.Windows.Threading;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Windows.Shapes;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Kaehler.scr
|
|
{
|
|
public partial class App : System.Windows.Application
|
|
{
|
|
/* private enum UpdateStatuses
|
|
{
|
|
NoUpdateAvailable,
|
|
UpdateAvailable,
|
|
UpdateRequired,
|
|
NotDeployedViaClickOnce,
|
|
DeploymentDownloadException,
|
|
InvalidDeploymentException,
|
|
InvalidOperationException
|
|
}*/
|
|
|
|
private void Application_Startup(object sender, StartupEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
CheckForExistingInstance();
|
|
if (e.Args.GetLength(0) > 0) // es gibt einen Parameter
|
|
{
|
|
// Normal screensaver mode.
|
|
if (e.Args[0].ToLower().StartsWith("/s"))
|
|
{
|
|
StartScreenSaver();
|
|
}
|
|
else // "/c" "/p" - Config, Preview mode
|
|
{
|
|
if (e.Args[0].ToLower().StartsWith("/c"))
|
|
{
|
|
System.Windows.MessageBox.Show("Es gibt noch keine Konfigurationsmöglichkeit.");
|
|
}
|
|
//if (e.Args[0].ToLower().StartsWith("/p"))
|
|
//{
|
|
// System.Windows.MessageBox.Show("Es gibt noch keine Preview.");
|
|
//}
|
|
System.Windows.Application.Current.Shutdown();
|
|
}
|
|
}
|
|
else // kein Parameter App-Mode
|
|
{
|
|
StartScreenSaver();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Exception in " + ex.Source + ": " + ex.Message);
|
|
System.Windows.MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void CheckForExistingInstance()
|
|
{
|
|
if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName.ToString()).Length > 1)
|
|
{
|
|
System.Windows.Application.Current.Shutdown();
|
|
}
|
|
}
|
|
|
|
private void StartScreenSaver()
|
|
{
|
|
try
|
|
{
|
|
/* Das Deployment funktioniert nicht für scr-Dateien ...
|
|
try
|
|
{
|
|
ApplicationDeployment updateCheck = ApplicationDeployment.CurrentDeployment;
|
|
UpdateCheckInfo info = updateCheck.CheckForDetailedUpdate();
|
|
//
|
|
if (info.UpdateAvailable)
|
|
{
|
|
UpdateApplication();
|
|
}
|
|
}
|
|
catch (Exception uex)
|
|
{
|
|
Console.WriteLine("Exception in " + uex.Source.ToString() + ": " + uex.Message);
|
|
//System.Windows.Forms.MessageBox.Show("Exception in " + uex.Source.ToString() + ": " + uex.Message);
|
|
}
|
|
*/
|
|
|
|
MainWindow ss = new MainWindow();
|
|
ss.WindowStartupLocation = WindowStartupLocation.Manual;
|
|
System.Drawing.Rectangle location;
|
|
if (Screen.PrimaryScreen != null) {
|
|
location = Screen.PrimaryScreen.Bounds;
|
|
ss.WindowState = WindowState.Maximized;
|
|
ss.Show();
|
|
ss.LayoutReset();
|
|
}
|
|
/* ******************************************************************* */
|
|
//creates window on other screens
|
|
foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
|
|
{
|
|
if (screen == System.Windows.Forms.Screen.PrimaryScreen)
|
|
continue;
|
|
|
|
MainWindow window = new MainWindow();
|
|
window.WindowStartupLocation = WindowStartupLocation.Manual;
|
|
location = screen.Bounds;
|
|
//covers entire monitor
|
|
window.Left = location.X - 7;
|
|
window.Top = location.Y - 7;
|
|
window.Width = location.Width + 14;
|
|
window.Height = location.Height + 14;
|
|
window.Show();
|
|
window.LayoutReset();
|
|
|
|
}
|
|
/* ******************************************************************* */
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(value: "Exception in " + ex.Source + ": " + ex.Message);
|
|
System.Windows.Forms.MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/* void bgWorker_DoWork(object sender, DoWorkEventArgs e)
|
|
{
|
|
UpdateCheckInfo info = null;
|
|
|
|
// Check if the application was deployed via ClickOnce.
|
|
if (!ApplicationDeployment.IsNetworkDeployed)
|
|
{
|
|
e.Result = UpdateStatuses.NotDeployedViaClickOnce;
|
|
return;
|
|
}
|
|
|
|
ApplicationDeployment updateCheck = ApplicationDeployment.CurrentDeployment;
|
|
|
|
try
|
|
{
|
|
info = updateCheck.CheckForDetailedUpdate();
|
|
}
|
|
catch (DeploymentDownloadException dde)
|
|
{
|
|
e.Result = UpdateStatuses.DeploymentDownloadException;
|
|
Console.WriteLine("Exception in " + dde.Source.ToString() + ": " + dde.Message);
|
|
return;
|
|
}
|
|
catch (InvalidDeploymentException ide)
|
|
{
|
|
e.Result = UpdateStatuses.InvalidDeploymentException;
|
|
Console.WriteLine("Exception in " + ide.Source.ToString() + ": " + ide.Message);
|
|
return;
|
|
}
|
|
catch (InvalidOperationException ioe)
|
|
{
|
|
e.Result = UpdateStatuses.InvalidOperationException;
|
|
Console.WriteLine("Exception in " + ioe.Source.ToString() + ": " + ioe.Message);
|
|
return;
|
|
}
|
|
|
|
if (info.UpdateAvailable)
|
|
if (info.IsUpdateRequired)
|
|
e.Result = UpdateStatuses.UpdateRequired;
|
|
else
|
|
e.Result = UpdateStatuses.UpdateAvailable;
|
|
else
|
|
e.Result = UpdateStatuses.NoUpdateAvailable;
|
|
}*/
|
|
|
|
/* void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
|
{
|
|
switch ((UpdateStatuses)e.Result)
|
|
{
|
|
case UpdateStatuses.NoUpdateAvailable:
|
|
// No update available, do nothing
|
|
System.Windows.Forms.MessageBox.Show("Es gibt kein Update, danke...");
|
|
break;
|
|
case UpdateStatuses.UpdateAvailable:
|
|
DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("Für den Screensaver gibt es ein Update. Jetzt einspielen?", "Update verfügbar", MessageBoxButtons.OKCancel);
|
|
if (dialogResult == DialogResult.OK)
|
|
UpdateApplication();
|
|
break;
|
|
case UpdateStatuses.UpdateRequired:
|
|
System.Windows.Forms.MessageBox.Show("Ein erforderliches Update ist verfügbar, dieses wird jetzt installiert.", "Update verfügbar", MessageBoxButtons.OK);
|
|
UpdateApplication();
|
|
break;
|
|
case UpdateStatuses.NotDeployedViaClickOnce:
|
|
System.Windows.Forms.MessageBox.Show("Is this deployed via ClickOnce?");
|
|
break;
|
|
case UpdateStatuses.DeploymentDownloadException:
|
|
System.Windows.Forms.MessageBox.Show("Whoops, couldn't retrieve info on this app...");
|
|
break;
|
|
case UpdateStatuses.InvalidDeploymentException:
|
|
System.Windows.Forms.MessageBox.Show("Cannot check for a new version. ClickOnce deployment is corrupt!");
|
|
break;
|
|
case UpdateStatuses.InvalidOperationException:
|
|
System.Windows.Forms.MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application.");
|
|
break;
|
|
default:
|
|
System.Windows.Forms.MessageBox.Show("Nanu?");
|
|
break;
|
|
}
|
|
}*/
|
|
|
|
/* private void UpdateApplication()
|
|
{
|
|
try
|
|
{
|
|
ApplicationDeployment updateCheck = ApplicationDeployment.CurrentDeployment;
|
|
updateCheck.Update();
|
|
System.Windows.MessageBox.Show("Der Screensaver wurde erneuert und wird daher jetzt beendet.");
|
|
System.Windows.Application.Current.Shutdown();
|
|
}
|
|
catch (DeploymentDownloadException dde)
|
|
{
|
|
System.Windows.MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde);
|
|
return;
|
|
}
|
|
}*/
|
|
}
|
|
|
|
|
|
}
|