Beispiel #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    SubscriberInfo = null;
                    Subscriber     = null;
                }

                foreach (FileInfo item in _tempFiles)
                {
                    try
                    {
                        DirFile.DeleteFile(item);
                    }
                    catch (Exception ex)
                    {
                        Errors.Save($"Не удалось удалить временный файл: {item.FullName}");
                        Errors.Save(ex);
                    }
                }
                _tempFiles.Clear();
                _tempFiles = null;

                disposedValue = true;
            }
        }
Beispiel #2
0
        private int?GetMaxVersionFile(bool getVersion = false)
        {
            string currentHash = GetMD5(SubscriberInfo.FullName);

            FileInfo fileInfoMaxEdited = null;
            DateTime dateTimeMaxEdited = DateTime.MinValue;

            foreach (FileInfo file in GetFilesInDirectoryVersion())
            {
                if (dateTimeMaxEdited <= file.LastWriteTime)
                {
                    fileInfoMaxEdited = file;
                    dateTimeMaxEdited = file.LastWriteTime;
                }
                ;
            }

            DateVersion = dateTimeMaxEdited;

            if (fileInfoMaxEdited == null)
            {
                return(0);
            }

            if (!getVersion)
            {
                if (GetMD5(fileInfoMaxEdited.FullName) == currentHash)
                {
                    return(null);
                }
            }

            return(DirFile.GetNumberVersion(fileInfoMaxEdited.Name));
        }
        private void MainWindowControlModifiedFiles_Loaded(object sender, RoutedEventArgs e)
        {
            _handlerLoadForm = true;

            SetItemSouceDataGridList();
            SetItemSourceVersion();

            ChangeVisiblePanelSettings(true);
            ChangeVisiblePanelVersion(true);
            ChangeVisibleComparer(false);
            ChangeVisibleButtonRestoreVersion();
            ChangeVisibleButtonAddCommentVersion();

            LoadUserSettings();
            ChangeVisibleModifiedSettings();

            _callUpdate.CallUpdateVersion      += UpdateVersion;
            _useContextMenu.CallUseContextMenu += EvokedContextMenu;

            SetIconShieldUAC();

            DirFile.DeleteTempFile();

            _handlerLoadForm = false;
        }
Beispiel #4
0
        internal void RestoreVersion(ListVersion version)
        {
            if (Subscriber == null)
            {
                return;
            }

            FileInfo fileInfoVersion = new FileInfo(version.Path);

            if (!DirFile.FileExists(fileInfoVersion))
            {
                return;
            }

            FileInfo tempFileVersion = new FileInfo(DirFile.GetTempFile());

            fileInfoVersion.CopyTo(tempFileVersion.FullName);
            tempFileVersion.LastWriteTime = DateTime.Now;

            FileInfo fileInfoRestore = new FileInfo(Subscriber.Path);

            tempFileVersion.CopyTo(fileInfoRestore.FullName, true);

            DirFile.DeleteFile(tempFileVersion);
        }
 private void DataGridListContextMenuOpenCatalog(object sender, RoutedEventArgs e)
 {
     if (DataGridList.SelectedItem is FileSubscriber subscriber)
     {
         DirFile.OpenDirectory(subscriber.DirectoryVersion);
     }
 }
        private void AddSelectedFilesIndgList(string[] fileNames)
        {
            List <FileSubscriber> list = listFile.ToList();

            foreach (string file in fileNames)
            {
                FileSubscriber finded = list.Find(f => f.Path == file);

                if (finded != null)
                {
                    Dialog.ShowMessage($"Выбранный файл уже контролируется:\n" +
                                       $"{fileNames}");
                    return;
                }

                DirFile pathInfo = new DirFile(file);

                ulong sizeFile = pathInfo.GetFileSize();

                FileSubscriber fileChecked = new FileSubscriber()
                {
                    Checked    = true,
                    Path       = file,
                    Size       = sizeFile,
                    SizeString = pathInfo.GetSizeFormat(sizeFile)
                };

                _subscriber.SubscribeChangeFile(fileChecked);

                list.Add(fileChecked);
            }

            SetItemSouce(list);
        }
 public ListVersion(string path, string fileName, DateTime dateModified, CommentsVersion commentVersion)
 {
     _path         = path;
     _fileName     = fileName;
     _dateModified = dateModified;
     _comment      = commentVersion?.Comment;
     _dateComment  = commentVersion?.DateTime;
     _version      = DirFile.GetNumberVersion(_fileName);
 }
        private void MiAddFiles_Click(object sender, RoutedEventArgs e)
        {
            string[] fileNames = new DirFile().GetFileChecked(this);

            if (fileNames == null)
            {
                return;
            }

            AddSelectedFilesIndgList(fileNames);
        }
        private FileSubscriber AddFileInDataGrid(string file, bool notified = false)
        {
            FileSubscriber subscriber = new FileSubscriber()
            {
                Checked  = true,
                Path     = file,
                FileName = DirFile.GetFileName(file)
            };

            subscriber.SetCurrentSize();

            _subscriber.Subscribe(subscriber, notified);

            listFiles.Add(subscriber);

            return(subscriber);
        }
        private void Subscribe_Changed(object sender, FileSystemEventArgs e)
        {
            try
            {
                Thread.Sleep(1000);

                FileInfo fileInfo = new FileInfo(e.FullPath);

                FileSubscriber subscriber = _listSubscriber.First(f => f.Key.FullName == fileInfo.FullName).Value;

                string   tempFileName = DirFile.GetTempFile();
                FileInfo fileInfoTemp = fileInfo.CopyTo(tempFileName);
                string   fileName     = fileInfo.Name;
                string   extension    = fileInfo.Extension;
                fileInfo = null;

                Task.Run(() =>
                {
                    lock (_locker)
                    {
                        using (Versions versions = new Versions()
                        {
                            SubscriberInfo = fileInfoTemp,
                            Subscriber = subscriber,
                            FileName = fileName,
                            Extension = extension
                        })
                        {
                            versions.CreateNewVersionFile();
                        }

                        _callUpdate.NeedNotified = true;
                        _callUpdate.Call(subscriber);

                        DirFile.DeleteFile(fileInfoTemp);

                        fileInfoTemp = null;
                    }
                });
            }
            catch (Exception ex)
            {
                Errors.Save(ex);
            }
        }
        internal ComparsionDefy()
        {
            Path = UserSettings.GetUserSettings("PathDefy");

            if (!string.IsNullOrWhiteSpace(Path))
            {
                if (DirFile.FileExists(Path))
                {
                    ProgramInstalled = true;
                }
                else
                {
                    ProgramInstalled = false;
                }
            }
            else
            {
                ProgramInstalled = false;
            }
        }
Beispiel #12
0
        private string GetMD5(string path)
        {
            string hash = String.Empty;

            try
            {
                using (MD5 md5 = MD5.Create())
                {
                    string fileNameTemp = DirFile.GetTempFile();

                    FileInfo fileInfoTemp = new FileInfo(fileNameTemp);
                    if (!fileInfoTemp.Exists)
                    {
                        new FileInfo(path).CopyTo(fileNameTemp);
                        _tempFiles.Add(fileInfoTemp);
                    }

                    using (FileStream stream = new FileStream(fileNameTemp, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        byte[] hashByte = md5.ComputeHash(stream);
                        hash = BitConverter.ToString(hashByte).Replace("-", "").ToLowerInvariant();
                        stream.Close();
                    }

                    md5.Clear();
                }
            }
            catch (FileNotFoundException)
            {
                Errors.Save($"Файл '{path}' перемещен или удален.");
            }
            catch (IOException ex)
            {
                Errors.Save(ex);
            }

            return(hash);
        }
 internal string SelectFile()
 => DirFile.SelectFile("Файл программы Defy", "Defy.exe|Defy.exe");
 internal void SetCurrentSize()
 {
     Size       = DirFile.GetFileSize(_path);
     SizeString = DirFile.GetSizeFormat(_size);
 }
 private void ButtonAddFiles_Click(object sender, RoutedEventArgs e)
 {
     AddFilesInDataGridList(DirFile.SelectNewFiles(this), sender == null);
 }