UpdateCreator.cs :  » Game » WBFSSync » DevConsole » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » WBFSSync 
WBFSSync » DevConsole » UpdateCreator.cs
//-------------------------------------
// WBFSSync - WBFSSync.exe
//
// Copyright 2009 Caian (mga Frst) <frost.omega@hotmail.com> :
//
// WBFSSync is Licensed under the terms of the Microsoft Reciprocal License (Ms-RL)
//
// UpdateCreator.cs:
//
// Classe que controla a criao de pacotes de atualizao
//
// Formato do arquivo UPDATE.inf
//
// VERSION: X.X.XX
// COREFILE: PATH|SIZE|VERSION|MD5 HASH - 128BIT
// ...
// LANGUAGE: PATH|SIZE
// ...
// SKIN: PATH|NUM FILES
// SKIN FILE PATH|SIZE
// ...
// ...
//
//-------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;

namespace DevConsole{
    static class UpdateCreator
    {
        //-------------------------------
        const String ProjectPath = "..\\..\\..\\";
        const String ReleasePath = "Releases\\";
        const String UpdatePath = "UPDATE\\";

        const String LanguagePath = "Language\\";
        const String SkinPath = "Skin\\";
        const String DefaultSkin = "AeroSeven";
        
        const String ChangelogFile = "changelog.txt";
        const String LicenseFile = "license.txt";
        const String UpdateInfFile = "UPDATE.inf";

        //-------------------------------
        internal static List<String> CoreFiles = new List<string>();
        internal static List<String> LanguageFiles = new List<string>();
        internal static List<String> SkinFiles = new List<string>();
        internal static String[] Changelog = new string[0];
        internal static String Version = "";

        //-------------------------------
        public static void UpdateCommand(String[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("makerelease VERSION");
                return;
            }

            CoreFiles.Clear();
            LanguageFiles.Clear();
            SkinFiles.Clear();
            Changelog = new string[0];
            Version = "";

            //Mdulos
            if(File.Exists("modules.txt"))
            {
                String[] modules = File.ReadAllLines("modules.txt");
                foreach (string module in modules)
                {
                    if (module.Length == 0) continue;
                    CoreFiles.Add(Path.GetFullPath(ProjectPath + module));
                }
            }

            //Idiomas
            String[] languages = Directory.GetFiles(ProjectPath + LanguagePath, "*.inf");
            LanguageFiles.AddRange(languages);

            //Skins
            String[] skins = Directory.GetDirectories(ProjectPath + SkinPath);
            foreach (string skin in skins)
            {
                string dirname = Path.GetFileName(skin);
                if (dirname.StartsWith("_")) continue;
                SkinFiles.Add(skin);
            }

            //Changelog
            if (File.Exists(ProjectPath + ChangelogFile))
            {
                Changelog = File.ReadAllLines(ProjectPath + ChangelogFile, Encoding.Default);
            }

            //

            Console.WriteLine("Loading GUI...");

            FormUpdateCreator form = new FormUpdateCreator();
            form.textBox_version.Text = args[1];
            form.richTextBox_changelog.Lines = Changelog;

            foreach (string corefile in CoreFiles)
                form.checkedListBox_corefiles.Items.Add(Path.GetFileNameWithoutExtension(corefile), true);

            foreach (string langfile in LanguageFiles) 
                form.checkedListBox_languagefiles.Items.Add(Path.GetFileNameWithoutExtension(langfile), true);

            foreach (string skinfile in SkinFiles) 
                form.checkedListBox_skinfiles.Items.Add(Path.GetFileNameWithoutExtension(skinfile), true);

            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

                //

                Changelog = form.richTextBox_changelog.Lines;
                Version = form.textBox_version.Text;

                for (int i = form.checkedListBox_corefiles.Items.Count - 1; i >= 0; i--)
                {
                    if (!form.checkedListBox_corefiles.GetItemChecked(i))
                        CoreFiles.RemoveAt(i);
                }

                for (int i = form.checkedListBox_languagefiles.Items.Count - 1; i >= 0; i--)
                {
                    if (!form.checkedListBox_languagefiles.GetItemChecked(i))
                        LanguageFiles.RemoveAt(i);
                }

                for (int i = form.checkedListBox_skinfiles.Items.Count - 1; i >= 0; i--)
                {
                    if (!form.checkedListBox_skinfiles.GetItemChecked(i))
                        SkinFiles.RemoveAt(i);
                }

                //

                CreateRelease();
            }

            //
            Console.WriteLine("Done\n");
        }

        //-------------------------------
        private static void CreateRelease()
        {
            Stream updatefile = File.Open(ProjectPath + UpdatePath + UpdateInfFile, FileMode.Create, FileAccess.Write,
                FileShare.Read);
            StreamWriter writer = new StreamWriter(updatefile, Encoding.Default);
            writer.WriteLine("VERSION:{0}", Version);

            String updatedir = ProjectPath + UpdatePath + Version + '\\';
            String updatedirsrv = UpdatePath + Version + '\\';

            String releasedir = ProjectPath + ReleasePath + Version + '\\';

            Directory.CreateDirectory(updatedir);

            Directory.CreateDirectory(releasedir);
            Directory.CreateDirectory(releasedir + LanguagePath);
            Directory.CreateDirectory(releasedir + SkinPath);

            //Mdulos

            foreach (String module in CoreFiles)
            {
                string version = "";
                string md5hash = "";
                long filesize = 0;

                FileInfo fi = new FileInfo(module);
                filesize = fi.Length;

                fi = null;

                Assembly assembly = Assembly.LoadFile(module);
                version = assembly.GetName().Version.ToString();
                assembly = null;

                FileStream f = File.OpenRead(module);
                MD5 md5 = MD5.Create();
                byte[] bhash = md5.ComputeHash(f);
                for (int i = 0; i < bhash.Length; i++) md5hash += bhash[i].ToString("X");

                md5 = null;
                f.Close();
                f = null;
                bhash = null;

                File.Copy(module, updatedir + Path.GetFileName(module), true);
                File.Copy(module, releasedir + Path.GetFileName(module), true);
                
                //-----------------

                writer.WriteLine("COREFILE:{0}{1}|{2}|{3}|{4}", updatedirsrv, Path.GetFileName(module), filesize, version,
                    md5hash);
            }

            //Idiomas
            foreach (String language in LanguageFiles)
            {
                //Sem hashing nesses arquivos...
                long filesize = 0;

                FileInfo fi = new FileInfo(language);
                filesize = fi.Length;

                fi = null;

                writer.WriteLine("LANGUAGE:{0}{1}|{2}", LanguagePath, Path.GetFileName(language), filesize);
                File.Copy(language, releasedir + LanguagePath + Path.GetFileName(language), true);
            }

            //Skin
            foreach (String skin in SkinFiles)
            {
                String[] files = Directory.GetFiles(skin);
                writer.WriteLine("SKIN:{0}{1}|{2}", SkinPath, Path.GetFileNameWithoutExtension(skin), files.Length);

                DirectoryInfo di = Directory.CreateDirectory(releasedir + SkinPath + Path.GetFileNameWithoutExtension(skin));

                foreach (String file in files)
                {
                    //Sem hashing nesses arquivos...
                    long filesize = 0;

                    FileInfo fi = new FileInfo(file);
                    filesize = fi.Length;

                    fi = null;

                    writer.WriteLine(":{0}|{1}", Path.GetFileName(file), filesize);
                    File.Copy(file, di.FullName + '\\' + Path.GetFileName(file), true);
                }
            }

            //Changelog

            File.WriteAllLines(ProjectPath + ChangelogFile, Changelog, Encoding.Default);
            File.Copy(ProjectPath + ChangelogFile, releasedir + ChangelogFile, true);

            //Licena
            File.Copy(ProjectPath + LicenseFile, releasedir + LicenseFile, true);

            writer.Close();
            writer = null;
            updatefile = null;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.