|
/*
SqlBuilder - an intelligent database tool
This file is part of SqlBuilder.
www.netcult.ch/elmue
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You find the GNU General Public License in the subfolder GNU
if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.IO;
using System.Net;
using System.Threading;
using System.Diagnostics;
using SqlBuilder.Forms;
namespace SqlBuilder
{
/// <summary>
/// Checks for a new version on the update server and displays a messagebox
/// An updatecheck happens only once every X days (Defaults.UpdateInterval)
/// </summary>
public class UpdateCheck
{
int ms32_Today;
public UpdateCheck()
{
// Get a value which increments every day (days which elapsed since 01.Jan.0001)
// Convert nanoseconds -> days: /micro/milli / sec /min /hour/day
ms32_Today = (int)(DateTime.Today.Ticks / 10 / 1000 / 1000 / 60 / 60 / 24);
int s32_Last = (int)Functions.RegistryRead(eReg.Main,"LastUpdateCheck", 0);
if (s32_Last + Defaults.UpdateInterval <= ms32_Today)
{
Thread i_Thread = new Thread(new ThreadStart(WorkThread));
i_Thread.Start();
}
}
private void WorkThread()
{
try
{
string s_Version = GetLatestVersion();
if (s_Version != Defaults.Version)
{
if (frmMsgBox.Ask(frmMain.Instance, "SqlBuilder version "+s_Version+" is available on the server.\nDo you want to download the latest version?"))
Functions.OpenFile(frmMain.Instance, Defaults.DownloadUrl, ProcessWindowStyle.Normal);
}
// If success --> write date to XML file
Functions.RegistryWrite(eReg.Main,"LastUpdateCheck", ms32_Today);
}
catch {}
}
/// <summary>
/// Reads the text file from the server which contains the version string e.g. "4.1"
/// </summary>
public string GetLatestVersion()
{
WebRequest i_Request = WebRequest.Create(Defaults.UpdateUrl);
i_Request.Method = "GET";
WebResponse i_Response = i_Request.GetResponse();
StreamReader i_Reader = new StreamReader(i_Response.GetResponseStream());
return i_Reader.ReadToEnd();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.