Commit c3a967ef by Pascal Bigot

--no commit message

parent fe6c5475
......@@ -912,5 +912,47 @@ namespace CommonLib
}
}
public void BuildStatFileInfo()
{
int iNbData = m_GestData.Count;
int iNbScreen = m_GestScreen.Count;
int iMoyItemPersScreen = 0;
for (int i = 0; i < m_GestScreen.Count; i++)
{
BTScreen scr = m_GestScreen[i] as BTScreen;
iMoyItemPersScreen += scr.Controls.Count;
}
iMoyItemPersScreen = iMoyItemPersScreen / iNbScreen;
int iNbTimer = m_GestTimer.Count;
int iNbFunction = m_GestFunction.Count;
int iNbLogger = m_GestLogger.Count;
int iFunctionMoyScriptLines;
int iNbTotalScriptCount;
int iFunctionMaxScriptLines;
for (int i = 0; i < m_GestFunction.Count; i++)
{
Function item = m_GestFunction[i] as Function;
if (item.ItemScripts.Count > 0)
{
foreach (string key in item.ItemScripts.ScriptKeys)
{
if (iFunctionMaxScriptLines < item.ItemScripts[key].Length)
iFunctionMaxScriptLines = item.ItemScripts[key].Length;
iFunctionMoyScriptLines += item.ItemScripts[key].Length;
iNbTotalScriptCount++;
}
}
}
iFunctionMoyScriptLines = iFunctionMoyScriptLines / iNbTotalScriptCount;
int iScreenItemMoyScriptLines;
int iScreenItemMaxScriptLines;
string commType = m_Comm.CommType;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace SmartAppUpdater
{
class AssemmblyFileUpdater
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace SmartAppUpdater
{
class FileDownloader
{
}
}
......@@ -7,40 +7,55 @@ using System.Reflection;
using System.Windows.Forms;
using System.Collections.Specialized;
using System.Diagnostics;
using CommonLib;
namespace SmartAppUpdater
{
class Program
{
private const string BetaFileUrl = "http://www.smartappsoftware.net/smartapp/autoupdateB/";
private const string FileUrl = "http://www.smartappsoftware.net/smartapp/autoupdate/";
private const string VersionInfoFile = "lastversioninfo.xml";
public const string BetaFileUrl = "http://www.smartappsoftware.net/smartapp/autoupdateB/";
public const string FileUrl = "http://www.smartappsoftware.net/smartapp/autoupdate/";
public const string VersionInfoFile = "lastversioninfo.xml";
#if BUILD_LANG
#if TEST_LANG
static Lang m_SingLangSys = new Lang(true, true);
#else
static Lang m_SingLangSys = new Lang(true, false);
#endif
#else
static Lang m_SingLangSys = new Lang();
#endif
public static Lang LangSys
{
get { return m_SingLangSys; }
}
/// <summary>
///
/// </summary>
/// <param name="args"></param>
[STAThread]
static void Main(string[] args)
{
if (!Directory.Exists(Application.StartupPath + "tmpUpdate"))
{
Directory.CreateDirectory(Application.StartupPath + Path.DirectorySeparatorChar + "tmpUpdate");
}
StringCollection arguments = new StringCollection();
arguments.AddRange(args);
if (arguments.Contains("-GenerateVersFile"))
{
GenerateVersionFile(arguments);
GenerateVersionFile();
return;
}
else
{
LangSys.Initialize(Cste.STR_DEV_LANG, "EN", "SmartAppUpdater");
Form mainForm = new UpdaterMainForm();
Application.Run(mainForm);
/*
StringCollection filesToUpdate = CheckUpdates(arguments);
DownloadFiles(arguments, filesToUpdate);
Console.ReadKey();
StartBatchCopy();
}
}*/
}
public static void StartBatchCopy()
......@@ -52,105 +67,10 @@ namespace SmartAppUpdater
}
/// <summary>
///
/// </summary>
/// <param name="arguments"></param>
/// <returns></returns>
private static StringCollection CheckUpdates(StringCollection arguments)
{
WebClient wc = new WebClient();
bool bFileDownloadOK = false;
Console.WriteLine("Recherche des mises à jour");
try
{
string downloadURL = FileUrl + VersionInfoFile;
if (arguments.Contains("-B"))
downloadURL = BetaFileUrl + VersionInfoFile;
string localFile = Application.StartupPath + Path.DirectorySeparatorChar + "tmpUpdate" + Path.DirectorySeparatorChar + VersionInfoFile;
wc.DownloadFile(downloadURL, localFile);
bFileDownloadOK = true;
}
catch (Exception e)
{
Console.WriteLine(string.Format("Erreur de récupération du fichier d'information des version ({0})", e.Message));
Console.WriteLine("Mise a jour interrompue");
}
finally
{
wc.Dispose();
}
if (bFileDownloadOK)
{
try
{
XmlDocument versionFile = new XmlDocument();
string localFile = Application.StartupPath + Path.DirectorySeparatorChar + "tmpUpdate" + Path.DirectorySeparatorChar + VersionInfoFile;
versionFile.Load(localFile);
XmlNode rootNode = versionFile.DocumentElement;
StringCollection listAssemblyToDownload = new StringCollection();
foreach (XmlNode node in rootNode.ChildNodes)
{
if (node.Name == "assemblyInfo")
{
XmlNode attrName = node.Attributes.GetNamedItem("fileName");
// il faut déjà trouver si l'assembly est présent
bool bLocalAssemblyExists = false;
string localAssemblyVersion = string.Empty;
try
{
Assembly asm = Assembly.LoadFrom(Application.StartupPath + Path.DirectorySeparatorChar + attrName.Value);
Version asmVer = asm.GetName().Version;
localAssemblyVersion = asmVer.ToString();
bLocalAssemblyExists = true;
}
catch (Exception /*asmEx*/)
{
}
if (bLocalAssemblyExists)
{
XmlNode attrVersion = node.Attributes.GetNamedItem("lastVersion");
string versionString = attrVersion.Value;
string[] remoteVersionIndices = versionString.Split('.');
string[] localVersionIndices = localAssemblyVersion.Split('.');
for (int i = 0; i < remoteVersionIndices.Length; i++)
{
int iRemoteIndice = int.Parse(remoteVersionIndices[i]);
int iLocalIndice = int.Parse(localVersionIndices[i]);
if (iRemoteIndice > iLocalIndice)
{
listAssemblyToDownload.Add(attrName.Value);
break;
}
}
}
else
{
// nouvel assembly à récupérer
listAssemblyToDownload.Add(attrName.Value);
}
}
}
if (listAssemblyToDownload.Count > 0)
{
Console.WriteLine(string.Format("Il y a {0} fichier(s) à mettre à jour", listAssemblyToDownload.Count));
return listAssemblyToDownload;
}
}
catch (Exception e)
{
Console.WriteLine(string.Format("Erreur de détéction des version ({0})", e.Message));
}
}
return null;
}
/// <summary>
///
/// génération automatique du fichier de version des assembly
/// </summary>
/// <param name="arguments"></param>
static void GenerateVersionFile(StringCollection arguments)
static void GenerateVersionFile()
{
string strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
StringCollection AssemblyList = new StringCollection();
......@@ -186,36 +106,5 @@ namespace SmartAppUpdater
}
versionFile.Save("lastversioninfo.xml");
}
/// <summary>
///
/// </summary>
/// <param name="arguments"></param>
/// <param name="FilesToUpdate"></param>
static public void DownloadFiles(StringCollection arguments, StringCollection FilesToUpdate)
{
if (FilesToUpdate != null)
{
foreach (string file in FilesToUpdate)
{
WebClient wc = new WebClient();
try
{
string downloadURL = FileUrl + file;
if (arguments.Contains("-B"))
downloadURL = BetaFileUrl + file;
wc.DownloadFile(downloadURL, Application.StartupPath + Path.DirectorySeparatorChar + "tmpUpdate" + Path.DirectorySeparatorChar + file);
Console.WriteLine("Fichier téléchargé : " + file);
}
catch (Exception e)
{
Console.WriteLine("erreur telechargement fichier : " + file);
Console.WriteLine(e.Message);
}
}
}
}
}
}
......@@ -6,7 +6,7 @@
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A3DF3670-EF60-48AD-A28D-3DABE0655844}</ProjectGuid>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SmartAppUpdater</RootNamespace>
<AssemblyName>SmartAppUpdater</AssemblyName>
......@@ -14,6 +14,7 @@
<FileAlignment>512</FileAlignment>
<StartupObject>
</StartupObject>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
......@@ -35,12 +36,21 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemmblyFileUpdater.cs" />
<Compile Include="FileDownloader.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UpdaterMainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UpdaterMainForm.Designer.cs">
<DependentUpon>UpdaterMainForm.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Content Include="local_lastversioninfo.xml">
......@@ -51,6 +61,17 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CommonLib\CommonLibVC9.csproj">
<Project>{3EFBC5AC-5842-4DE5-85C2-507E24AEC46F}</Project>
<Name>CommonLibVC9</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="UpdaterMainForm.resx">
<DependentUpon>UpdaterMainForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......@@ -60,6 +81,7 @@
</Target>
-->
<PropertyGroup>
<PostBuildEvent>$(TargetPath) -GenerateVersFile</PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>
\ No newline at end of file
namespace SmartAppUpdater
{
partial class UpdaterMainForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(12, 12);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(140, 17);
this.checkBox1.TabIndex = 1;
this.checkBox1.Text = "Search for beta updates";
this.checkBox1.UseVisualStyleBackColor = true;
//
// textBox1
//
this.textBox1.AcceptsReturn = true;
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox1.Location = new System.Drawing.Point(12, 54);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(367, 248);
this.textBox1.TabIndex = 2;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 35);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(37, 13);
this.label1.TabIndex = 3;
this.label1.Text = "Status";
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(261, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(118, 23);
this.button1.TabIndex = 4;
this.button1.Text = "Update";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// UpdaterMainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(391, 314);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.checkBox1);
this.Name = "UpdaterMainForm";
this.Text = "SmartApp Updater";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CommonLib;
using System.Net;
using System.IO;
using System.Xml;
using System.Reflection;
namespace SmartAppUpdater
{
public partial class UpdaterMainForm : Form
{
private const string ENDL = "\r\n";
public UpdaterMainForm()
{
InitializeComponent();
}
protected void AddStatusLine(string message)
{
textBox1.Text += message;
Application.DoEvents();
}
protected bool DownloadVersionFile()
{
textBox1.Text = string.Empty;
WebClient wc = new WebClient();
bool bFileDownloadOK = false;
if (!Directory.Exists(Application.StartupPath + "tmpUpdate"))
{
Directory.CreateDirectory(Application.StartupPath + Path.DirectorySeparatorChar + "tmpUpdate");
}
try
{
AddStatusLine(Program.LangSys.C("Cheking for updates") + ENDL);
string downloadURL = Program.FileUrl + Program.VersionInfoFile;
if (checkBox1.Checked) // version Beta
downloadURL = Program.BetaFileUrl + Program.VersionInfoFile;
string localFile = Application.StartupPath + Path.DirectorySeparatorChar + "tmpUpdate" + Path.DirectorySeparatorChar + Program.VersionInfoFile;
wc.DownloadFile(downloadURL, localFile);
bFileDownloadOK = true;
}
catch (Exception e)
{
AddStatusLine(string.Format(Program.LangSys.C("Error while looking for version file ({0})", e.Message)) + ENDL);
AddStatusLine(Program.LangSys.C("Update canceled") + ENDL);
}
finally
{
wc.Dispose();
}
if (bFileDownloadOK)
{
AddStatusLine(Program.LangSys.C("Version file updated") + ENDL);
}
return bFileDownloadOK;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private StringCollection CheckVersions()
{
try
{
AddStatusLine(Program.LangSys.C("Detecting local version") + ENDL);
XmlDocument versionFile = new XmlDocument();
string localFile = Application.StartupPath + Path.DirectorySeparatorChar + "tmpUpdate" + Path.DirectorySeparatorChar + Program.VersionInfoFile;
versionFile.Load(localFile);
XmlNode rootNode = versionFile.DocumentElement;
StringCollection listAssemblyToDownload = new StringCollection();
foreach (XmlNode node in rootNode.ChildNodes)
{
if (node.Name == "assemblyInfo")
{
XmlNode attrName = node.Attributes.GetNamedItem("fileName");
XmlNode attrVersion = node.Attributes.GetNamedItem("lastVersion");
// il faut déjà trouver si l'assembly est présent
bool bLocalAssemblyExists = false;
string localAssemblyVersion = string.Empty;
try
{
Assembly asm = Assembly.LoadFrom(Application.StartupPath + Path.DirectorySeparatorChar + attrName.Value);
Version asmVer = asm.GetName().Version;
localAssemblyVersion = asmVer.ToString();
bLocalAssemblyExists = true;
}
catch (Exception /*asmEx*/)
{
}
if (bLocalAssemblyExists)
{
string versionString = attrVersion.Value;
string[] remoteVersionIndices = versionString.Split('.');
string[] localVersionIndices = localAssemblyVersion.Split('.');
for (int i = 0; i < remoteVersionIndices.Length; i++)
{
int iRemoteIndice = int.Parse(remoteVersionIndices[i]);
int iLocalIndice = int.Parse(localVersionIndices[i]);
if (iRemoteIndice > iLocalIndice)
{
listAssemblyToDownload.Add(attrName.Value);
AddStatusLine(string.Format(
Program.LangSys.C("Component {0} must be updated (local version = {1}, server version = {2})"),
attrName.Value,
localAssemblyVersion,
attrVersion.Value) + ENDL);
break;
}
}
}
else
{
// nouvel assembly à récupérer
AddStatusLine(string.Format(
Program.LangSys.C("Component {0} is not present on your system and will be acquired (server version = {1})"),
attrName.Value,
attrVersion.Value) + ENDL);
listAssemblyToDownload.Add(attrName.Value);
}
}
}
if (listAssemblyToDownload.Count > 0)
{
AddStatusLine(Program.LangSys.C(
string.Format("Total : {0} file will be downloaded",
listAssemblyToDownload.Count)) + ENDL);
return listAssemblyToDownload;
}
}
catch (Exception e)
{
AddStatusLine(string.Format(Program.LangSys.C("Error while detecting versions ({0})"), e.Message) + ENDL);
}
return null;
}
/// <summary>
///
/// </summary>
/// <param name="arguments"></param>
/// <param name="FilesToUpdate"></param>
public bool DownloadFiles(StringCollection FilesToUpdate)
{
bool bAllFileOK = true;
if (FilesToUpdate != null)
{
foreach (string file in FilesToUpdate)
{
AddStatusLine(Program.LangSys.C(
string.Format("Downloading file {0}",
file)) + ENDL);
WebClient wc = new WebClient();
try
{
string downloadURL = Program.FileUrl + file;
if (checkBox1.Checked)
downloadURL = Program.BetaFileUrl + file;
wc.DownloadFile(downloadURL, Application.StartupPath + Path.DirectorySeparatorChar + "tmpUpdate" + Path.DirectorySeparatorChar + file);
AddStatusLine(Program.LangSys.C("Done") + ENDL);
}
catch (Exception e)
{
AddStatusLine(Program.LangSys.C(
string.Format("Error while downloading file {0} ({1})",
file, e.Message)) + ENDL);
bAllFileOK = false;
break;
}
}
}
return bAllFileOK;
}
private void button1_Click(object sender, EventArgs e)
{
if (DownloadVersionFile())
{
StringCollection assemblyToDownload = CheckVersions();
if (assemblyToDownload == null)
{
AddStatusLine(Program.LangSys.C("Your version is already up to date") + ENDL);
}
else
{
if (DownloadFiles(assemblyToDownload))
{
MessageBox.Show(Program.LangSys.C("Updater will now close and finalize update, do not try so start SmartApp before the console windows is closed"), Program.LangSys.C("Information"));
Program.StartBatchCopy();
Application.Exit();
}
}
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64