Exemple #1
0
        public void InsertMatchedApplication(MatchedApplication info)
        {
            if (MatchedAppInfos.Items.All(i => i.ApplicationId != info.ApplicationId))
            {
                var fileInfo       = new FileInfo(info.OriginalFile);
                var dirName        = Path.GetFileNameWithoutExtension(info.OriginalFile);
                var applicationDir = $"{RootApplicationDirectory}{dirName}\\";

                FileService.DirectoryCopy(fileInfo.DirectoryName, applicationDir, true);
                info.ExecuteFile = $"{applicationDir}{info.ApplicationName}";

                Observable.Start(() =>
                {
                    info.SetIcon(info.ExecuteFile);
                    MatchedAppInfos.Add(info);
                }, RxApp.MainThreadScheduler);
            }
            else
            {
                var targetInfo = MatchedAppInfos.Items.FirstOrDefault(i => i.ApplicationId == info.ApplicationId);
                if (targetInfo != null)
                {
                    targetInfo.OriginalFile = info.OriginalFile;
                    var fileInfo       = new FileInfo(targetInfo.OriginalFile);
                    var dirName        = Path.GetFileNameWithoutExtension(info.OriginalFile);
                    var applicationDir = $"{RootApplicationDirectory}{dirName}\\";

                    FileService.DirectoryCopy(fileInfo.DirectoryName, applicationDir, true);
                    info.ExecuteFile = $"{applicationDir}{info.ApplicationName}";
                }
            }
        }
Exemple #2
0
        public void UpdateMatchedApplication(MatchedApplication app, string orgFile)
        {
            try
            {
                var fileInfo       = new FileInfo(orgFile);
                var applicationDir = Path.GetDirectoryName(app.ExecuteFile);

                FileService.DirectoryCopy(fileInfo.DirectoryName, applicationDir, true);
                app.OriginalFile = orgFile;
            }
            catch
            {
            }
        }
Exemple #3
0
        /// <summary>
        /// 최신 프로그램이 존재여부를 검사합니다.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="token"></param>
        /// <returns>최신 프로그램이 존재하면 최신파일경로, 그렇지 않으면 string.Empty</returns>
        public async Task <string> UpdateCheck(MatchedApplication app, CancellationToken token)
        {
            return(await FileService.SearchAsync(RootPaths, app.ApplicationName, token)
                   .ContinueWith(t =>
            {
                var searchedFile = t.Result;
                var appFileInfo = new FileInfo(app.ExecuteFile);
                var searchedFileInfo = new FileInfo(searchedFile);

                if (appFileInfo.LastWriteTime < searchedFileInfo.LastWriteTime)
                {
                    return searchedFile;
                }
                return string.Empty;
            }, token));
        }
Exemple #4
0
        private MatchedApplication CreateMatchedApplication(Guid appId, string fileName, string file)
        {
            if (MatchedAppInfos.Items.All(appInfo => appInfo.ApplicationName != fileName))
            {
                var header     = Path.GetFileNameWithoutExtension(fileName);
                var newAppInfo = new MatchedApplication(header)
                {
                    ApplicationId   = appId,
                    ApplicationName = fileName,
                    OriginalFile    = file
                };
                return(newAppInfo);
            }

            return(null);
        }
        public static bool LoadConfigurationFile(string filePath, ICollection <string> rootPaths, ICollection <ApplicationModel> appNames, ISourceList <MatchedApplication> infos)
        {
            try
            {
                var doc = XDocument.Load(filePath);
                if (doc.Root == null)
                {
                    return(false);
                }

                var rootPathsElement = doc.Root.Element("RootPaths");
                var appNamesElement  = doc.Root.Element("AppModels");
                var appInfoElement   = doc.Root.Element("AppInfos");
                if (rootPathsElement != null)
                {
                    foreach (var e in rootPathsElement.Elements("RootPath"))
                    {
                        rootPaths.Add(e.Value);
                    }
                }


                if (appNamesElement != null)
                {
                    foreach (var e in appNamesElement.Elements("AppModel"))
                    {
                        Guid id = Guid.Empty;

                        var appId = e.Element("AppId");
                        if (appId != null)
                        {
                            if (!Guid.TryParse(appId.Value, out id))
                            {
                                throw new ArgumentException("Id cannot be null");
                            }
                        }

                        string fileName = string.Empty;

                        var fileNameElement = e.Element("FileName");
                        if (fileNameElement != null)
                        {
                            fileName = fileNameElement.Value;
                        }

                        if (string.IsNullOrEmpty(fileName))
                        {
                            throw new ArgumentException("FileName cannot be null");
                        }
                        var appModel = new ApplicationModel(id, fileName);
                        appNames.Add(appModel);
                    }
                }
                if (appInfoElement != null)
                {
                    foreach (var e in appInfoElement.Elements("AppInfo"))
                    {
                        var matchedAppInfo = new MatchedApplication();
                        var appName        = e.Element("AppName");

                        if (appName != null)
                        {
                            matchedAppInfo.ApplicationName = appName.Value;
                        }
                        var orgFile = e.Element("OrgFile");

                        if (orgFile != null)
                        {
                            matchedAppInfo.OriginalFile = orgFile.Value;
                        }
                        var exeFile = e.Element("ExeFile");

                        if (exeFile != null)
                        {
                            matchedAppInfo.ExecuteFile = exeFile.Value;
                            if (File.Exists(exeFile.Value))
                            {
                                matchedAppInfo.SetIcon(exeFile.Value);
                            }
                        }

                        var header = e.Element("Header");
                        if (header != null)
                        {
                            matchedAppInfo.Header = header.Value;
                        }

                        infos.Add(matchedAppInfo);
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
 public void UpdateInfo(MatchedApplication newApp)
 {
     MatchedAppUpdate?.Invoke(newApp);
 }