コード例 #1
0
        private void InitializeFileWatcher()
        {
            if (WatchedFile.IsBlank())
            {
                throw Fault.NullRef(nameof(WatchedFile));
            }

            if (!File.Exists(WatchedFile))
            {
                throw Fault.MissingFile(WatchedFile);
            }

            var abs = WatchedFile.MakeAbsolute();
            var dir = Path.GetDirectoryName(abs);
            var nme = Path.GetFileName(abs);

            _watchr = new FileSystemWatcher(dir, nme);
            _watchr.NotifyFilter = NotifyFilters.LastWrite;
            _watchr.Changed     += async(s, e) =>
            {
                if (!_isDelaying)
                {
                    _isDelaying = true;
                    await Task.Delay(1000);

                    IsFileChanged = true;
                    OnFileChanged();
                    _isDelaying = false;
                }
            };
            _watchr.EnableRaisingEvents = true;
        }
コード例 #2
0
        private void RelaunchInTemp()
        {
            if (WatchedFile.IsBlank())
            {
                return;
            }
            var exeNow = CurrentExe.GetFullPath();
            var cfgNow = exeNow + ".config";
            var tmpExe = WatchedFile.MakeTempCopy(".exe");
            var tmpCfg = tmpExe + ".config";

            if (File.Exists(cfgNow))
            {
                File.Copy(cfgNow, tmpCfg, true);
            }

            Process.Start(tmpExe, GetCommandLineArgs());
            Application.Current.Shutdown();
        }
コード例 #3
0
        private void RelaunchInTemp()
        {
            if (WatchedFile.IsBlank())
            {
                return;
            }
            var tmpExe = "";

            try
            {
                tmpExe = WatchedFile.MakeTempCopy(".exe");
            }
            catch (Exception ex)
            {
                Alert.Show(ex, $"Creating temp copy of {WatchedFile}");
                return;
            }
            CopyCfgToTemp(tmpExe);

            Process.Start(tmpExe, GetCommandLineArgs());
            Application.Current.Shutdown();
        }