프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / MarkusAutoUpdate / src / NetSparkle.Samples.NetFramework.WPF / App.xaml.cs @ 77cdac33

이력 | 보기 | 이력해설 | 다운로드 (3.46 KB)

1
using log4net;
2
using NetSparkle.TestAppWPF.Common;
3
using NetSparkle.TestAppWPF.ViewModel;
4
using Salaros.Configuration;
5
using System;
6
using System.Collections.Generic;
7
using System.Configuration;
8
using System.Data;
9
using System.Globalization;
10
using System.Linq;
11
using System.Windows;
12

    
13
namespace NetSparkleUpdater.Samples.NetFramework.WPF
14
{
15
    /// <summary>
16
    /// Interaction logic for App.xaml
17
    /// </summary>
18
    public partial class App : Application
19
    {
20
        public static string KcomParam = null;
21
        public static string AppCastUri = null;
22
        public static bool IsExternal = false;
23
        public static string ExternalAddress = null;
24
        public static ExtractParam extractParam = null;
25

    
26
        public static bool IsExtract = false;
27

    
28
        public static ILog logger = LogManager.GetLogger(typeof(App));
29

    
30
        public App()
31
        {
32

    
33
        }
34

    
35
        protected override void OnStartup(StartupEventArgs e)
36
        {
37
            try
38
            {
39
                var startDir = AppDomain.CurrentDomain.BaseDirectory;
40
                var configFilePath = $"{System.IO.Path.Combine(startDir, "Markus.AppUpdate.ini")}";
41

    
42
                var config = new ConfigParser(configFilePath,
43
                                new ConfigParserSettings
44
                                {
45
                                    MultiLineValues = MultiLineValues.Simple | MultiLineValues.AllowValuelessKeys | MultiLineValues.QuoteDelimitedValues,
46
                                    Culture = new CultureInfo("en-US")
47
                                });
48

    
49
                AppCastUri = config.GetValue("APP_CAST", "URI");
50

    
51
                var hostDomain = config.GetValue("HOST_DOMAIN", "DOMAIN");
52

    
53
                if(hostDomain != null)
54
                {
55
                    var hostEntry = DnsHelper.GetHostEntryTask();
56

    
57
                    if(hostEntry == null)
58
                    {
59
                        IsExternal = true;
60
                    }
61
                    else if(!string.IsNullOrWhiteSpace(hostDomain) && !hostEntry.HostName.ToUpper().EndsWith(hostDomain.ToUpper()))
62
                    {
63
                        IsExternal = true;
64
                    }
65
                }
66

    
67
                if (IsExternal)
68
                {
69
                    ExternalAddress = config.GetValue("APP_CAST", "EXTERNAL_URI");
70

    
71
                    var uri = UriHelper.ChangeAddress(new Uri(AppCastUri), ExternalAddress);
72
                    
73
                    AppCastUri = uri.ToString();
74
                }
75
               
76

    
77
                App.logger.Info($"App Cast Uri : {AppCastUri}");
78

    
79
                if (e.Args.Count() > 0)
80
                {
81
                    if (e.Args[0] == "EXT" && e.Args.Count() == 2)
82
                    {
83
                        App.extractParam = ObjectToBytesStringConvert.BytesStringToObject<ExtractParam>(e.Args[1]);
84
                        App.IsExtract = true;
85
                    }
86
                    else if (e.Args[0] == "ADMIN" && e.Args.Count() == 2)
87
                    {
88
                        App.extractParam = ObjectToBytesStringConvert.BytesStringToObject<ExtractParam>(e.Args[1]);
89
                        App.KcomParam = App.extractParam.AppRunParam;
90
                    }
91
                    else
92
                    {
93
                        KcomParam = e.Args[0];
94
                    }
95
                }
96

    
97
                base.OnStartup(e);
98
            }
99
            catch (Exception ex) 
100
            {
101
                logger.Error("Startup Error ", ex);
102
            }
103
        }
104
    }
105
}
클립보드 이미지 추가 (최대 크기: 500 MB)