Check-in [52618a78f2]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:If a file name is passed, that is interpreted as a zip file; the updater will attempt to update ZTreeWin from that file.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | develop
Files: files | file ages | folders
SHA1: 52618a78f238dc8b94b96cdc758c986a7680e9fe
User & Date: tinus 2018-03-21 21:42:57
Context
2018-03-21
21:51
Simplified(?) handling of aggregate exceptions. check-in: d8049380d5 user: tinus tags: develop
21:42
If a file name is passed, that is interpreted as a zip file; the updater will attempt to update ZTreeWin from that file. check-in: 52618a78f2 user: tinus tags: develop
21:05
Only update when the version is actually higher. Respect the executable's current caps. check-in: 1909930a85 user: tinus tags: develop
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ZTUpdater/Program.cs.

1
2
3
4

5
6
7
8
9
10
11
..
12
13
14
15
16
17
18

19
20
21

22


23
24
25
26
27
28
29


30
31
32
33




34
35
36
37
38
39
40
..
52
53
54
55
56
57
58







59
60
61
62














63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;


namespace ZTUpdater
{
    class Program
    {
        [STAThread]
        static int Main(string[] args)
................................................................................
        {
            try
            {
                // Read the command-line options
                var MinimumLevel = TraceLevel.Info;
                string OptName = null;
                var Options = new Dictionary<string, string>();

                foreach (var arg in args)
                {
                    if (OptName != null)

                        Options.Add(OptName, arg);


                    else if (arg == "/?" || arg == "/h" || arg == "/help")
                    {
                        ShowHelp();
                        return 0;
                    }
                    else if (arg == "/v" || arg == "/verbose")
                        MinimumLevel = TraceLevel.Verbose;


                    else if (arg == "/b" || arg == "/backup")
                        OptName = "backup";
                    else if (arg == "/a" || arg == "/archive")
                        OptName = "archive";




                }

                // Initialize the updater component
                var Updater = new ZTWUpdater()
                {
                    OnLog = WriteLog(MinimumLevel)
                };
................................................................................
                }
                if (Options.TryGetValue("archive", out var Value))
                    Updater.ArchiveDir = new System.IO.DirectoryInfo(Value);
                else if (Options.TryGetValue("backup", out Value))
                    Updater.BackupDir = new System.IO.DirectoryInfo(Value);

                // Perform the actual update







                var UpdateTask = Updater.Update();
                UpdateTask.Wait();
                WriteLog(MinimumLevel)($"{UpdateTask.Result} files updated.", TraceLevel.Info);
                return UpdateTask.Result > 0 ? 0 : 1;














            }
            catch (Exception ex)
            {
                var BackupColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Error.WriteLine(ex.ToString());
                Console.ForegroundColor = BackupColor;
                return 255;
            }
        }

        private static void ShowHelp()
        {




>







 







>



>

>
>







>
>




>
>
>
>







 







>
>
>
>
>
>
>
|
|
<
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>





|







1
2
3
4
5
6
7
8
9
10
11
12
..
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
..
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;

namespace ZTUpdater
{
    class Program
    {
        [STAThread]
        static int Main(string[] args)
................................................................................
        {
            try
            {
                // Read the command-line options
                var MinimumLevel = TraceLevel.Info;
                string OptName = null;
                var Options = new Dictionary<string, string>();
                var Arguments = new List<string>();
                foreach (var arg in args)
                {
                    if (OptName != null)
                    {
                        Options.Add(OptName, arg);
                        OptName = null;
                    }
                    else if (arg == "/?" || arg == "/h" || arg == "/help")
                    {
                        ShowHelp();
                        return 0;
                    }
                    else if (arg == "/v" || arg == "/verbose")
                        MinimumLevel = TraceLevel.Verbose;
                    else if (arg == "/H" || arg == "/home")
                        OptName = "home";
                    else if (arg == "/b" || arg == "/backup")
                        OptName = "backup";
                    else if (arg == "/a" || arg == "/archive")
                        OptName = "archive";
                    else if (arg.StartsWith("/"))
                        WriteLog(MinimumLevel)($"Unrecognized option '{arg}'", TraceLevel.Warning);
                    else
                        Arguments.Add(arg);
                }

                // Initialize the updater component
                var Updater = new ZTWUpdater()
                {
                    OnLog = WriteLog(MinimumLevel)
                };
................................................................................
                }
                if (Options.TryGetValue("archive", out var Value))
                    Updater.ArchiveDir = new System.IO.DirectoryInfo(Value);
                else if (Options.TryGetValue("backup", out Value))
                    Updater.BackupDir = new System.IO.DirectoryInfo(Value);

                // Perform the actual update
                int FilesUpdated;
                if (Arguments.Count > 0)
                {
                    FilesUpdated = Updater.UpdateFromFile(Arguments[0]);
                }
                else
                {
                    var UpdateTask = Updater.UpdateAsync();
                    UpdateTask.Wait();

                    FilesUpdated = UpdateTask.Result;
                }
                WriteLog(MinimumLevel)($"{FilesUpdated} files updated.", TraceLevel.Info);
                return FilesUpdated > 0 ? 0 : 1;
            }
            catch (AggregateException aex)
            {
                var BackupColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Magenta;
                aex.Handle((ex) => {
                    Console.Error.WriteLine(ex.Message);
                    return true;
                });
                Console.ForegroundColor = BackupColor;
                return 255;
            }
            catch (Exception ex)
            {
                var BackupColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Error.WriteLine(ex.Message);
                Console.ForegroundColor = BackupColor;
                return 255;
            }
        }

        private static void ShowHelp()
        {

Changes to ZTUpdater/ZTUpdater.cs.

154
155
156
157
158
159
160




161
162
163
164
165
166
167
168
...
210
211
212
213
214
215
216





217
218
219
220
221
222
223
        public bool IsVersionNewer(string newVersion, string oldVersion)
        {
            var New = new Version(newVersion);
            var Old = new Version(oldVersion);
            return newVersion.CompareTo(oldVersion) > 0;
        }





        public async Task<int> Update()
        {
            Log($"ZTreeWin version {CurrentVersion} located in \"{ZTreeHome}\".", TraceLevel.Info);
            if (!Directory.Exists(ZTreeHome))
                throw new DirectoryNotFoundException($"Directory \"{ZTreeHome}\" not found");

            var DownloadUri = await GetUriLatestVersion();
            if (DownloadUri == null)
................................................................................
                }
            }

            // Perform the update based on the downloaded file
            return UpdateFromFile(ZipFile);
        }






        public int UpdateFromFile(string zipFile)
        {
            if (zipFile == null)
                throw new ArgumentNullException(nameof(zipFile));

            int NumFiles = 0;
            Log($"Extracting files...");







>
>
>
>
|







 







>
>
>
>
>







154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
...
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
        public bool IsVersionNewer(string newVersion, string oldVersion)
        {
            var New = new Version(newVersion);
            var Old = new Version(oldVersion);
            return newVersion.CompareTo(oldVersion) > 0;
        }

        /// <summary>
        /// Checks for an updated version of ZTreeWin; and if found, download and install it.
        /// </summary>
        /// <returns>The number of files that were updated.</returns>
        public async Task<int> UpdateAsync()
        {
            Log($"ZTreeWin version {CurrentVersion} located in \"{ZTreeHome}\".", TraceLevel.Info);
            if (!Directory.Exists(ZTreeHome))
                throw new DirectoryNotFoundException($"Directory \"{ZTreeHome}\" not found");

            var DownloadUri = await GetUriLatestVersion();
            if (DownloadUri == null)
................................................................................
                }
            }

            // Perform the update based on the downloaded file
            return UpdateFromFile(ZipFile);
        }

        /// <summary>
        /// Updates ZTreeWin using the contents of the given <paramref name="zipFile"/>.
        /// </summary>
        /// <param name="zipFile">The .zip file containing the updated version of ZTreeWin.</param>
        /// <returns>The number of files that were extracted from the <paramref name="zipFile"/>.</returns>
        public int UpdateFromFile(string zipFile)
        {
            if (zipFile == null)
                throw new ArgumentNullException(nameof(zipFile));

            int NumFiles = 0;
            Log($"Extracting files...");