Esempio n. 1
0
        public static void SortFile(FileInfo file)
        {
            Rule rule = null;

            try
            {
                if (file.Exists == false)
                {
                    return;
                }

                rule = FindRule(file.Name);
                var fileName = GenerateFileName(Path.GetFileName(file.Name));
                File.Move(file.FullName,
                          Path.Combine(rule.DestinationFolder, fileName ?? throw new InvalidOperationException()));

                var data = new MoveFileData(file.Name, rule.Name, rule.DestinationFolder);
                MainWindow.Instance.AddLog(data);
                Server.AddLog(data);
                MoveNotifier.Add(data);

                // TODO: Add notification
            }
            catch (DirectoryNotFoundException)
            {
                Directory.CreateDirectory(rule?.DestinationFolder ?? throw new InvalidOperationException());
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                // TODO: Add error handling for file moving
            }
        }
Esempio n. 2
0
        public FileLog(MoveFileData data)
        {
            InitializeComponent();
            this.data = data;

            var fullPath = data.Destination + "\\" + data.FileName;

            try
            {
                var destination       = data.Destination.Split('\\');
                var destinationString = "";
                var i = destination.Length;
                while (destinationString.Length < 20)
                {
                    destinationString = destination[--i] + "\\" + destinationString;
                }

                FileNameLabel.Content     = data.FileName;
                FileLocationLabel.Content = @"...\" + destinationString;
                FileTypeLabel.Content     = data.FileType;
                FileImage.Source          = Helper.FileToImageConverter(data.Destination + "\\" + data.FileName);
                FileTimeLabel.Content     = DateTime.Parse(data.Time).ToLocalTime();
                return;
            }
            catch (FileNotFoundException)
            {
                Server.DeleteLog(data);
                FileLogger.Remove(this);
            }
            catch (ArgumentNullException)
            {
                FileTimeLabel.Content = "PARSE ERROR";
            }
        }
Esempio n. 3
0
 public static void AddLog(MoveFileData data)
 {
     using (var db = new LiteDatabase(@".\Data.db"))
     {
         db.GetCollection <MoveFileData>(nameof(MoveFileData)).Insert(data);
     }
 }
Esempio n. 4
0
 public static void DeleteLog(MoveFileData data)
 {
     using (var db = new LiteDatabase(@".\Data.db"))
     {
         db.GetCollection <MoveFileData>(nameof(MoveFileData)).Delete(log => log.Equals(data));
     }
 }
Esempio n. 5
0
        /// <summary>
        /// move a virtual cluster for a file to a logical cluster on disk, repeat for count clusters
        /// </summary>
        /// <param name="deviceName">device to move on"c:"</param>
        /// <param name="path">file to muck with "c:\windows\explorer.exe"</param>
        /// <param name="VCN">cluster number in file to move</param>
        /// <param name="LCN">cluster on disk to move to</param>
        /// <param name="count">for how many clusters</param>
        static public void MoveFile(string deviceName, string path, Int64 VCN, Int64 LCN, Int32 count)
        {
            IntPtr hVol  = IntPtr.Zero;
            IntPtr hFile = IntPtr.Zero;

            try
            {
                hVol = OpenVolume(deviceName);

                hFile = OpenFile(path);


                MoveFileData mfd = new MoveFileData
                {
                    hFile        = hFile,
                    StartingVCN  = VCN,
                    StartingLCN  = LCN,
                    ClusterCount = count
                };

                GCHandle handle  = GCHandle.Alloc(mfd, GCHandleType.Pinned);
                IntPtr   p       = handle.AddrOfPinnedObject();
                uint     bufSize = (uint)Marshal.SizeOf(mfd);
                uint     size    = 0;

                bool fResult = DeviceIoControl(
                    hVol,
                    FSConstants.FSCTL_MOVE_FILE,
                    p,
                    bufSize,
                    IntPtr.Zero, // no output data from this FSCTL
                    0,
                    ref size,
                    IntPtr.Zero);

                handle.Free();

                if (!fResult)
                {
                    throw new Exception(Marshal.GetLastWin32Error().ToString());
                }
            }
            finally
            {
                CloseHandle(hVol);
                CloseHandle(hFile);
            }
        }
Esempio n. 6
0
        public static void Add(MoveFileData data)

        {
            var desktopWorkingArea = SystemParameters.WorkArea;
            var log = new MoveLogNotifier(data);

            log.Left = desktopWorkingArea.Right - log.Width - 20;
            log.Top  = desktopWorkingArea.Bottom - log.Height - 20;
            foreach (var moveLogNotifier in _logs)
            {
                var _ = new TimedDispatcher(20, TimeSpan.FromMilliseconds(1), (sender, args) =>
                {
                    moveLogNotifier.Top -= 5;
                });
            }

            _logs.AddLast(log);
            log.Show();
        }
        public MoveLogNotifier(MoveFileData data) : this()
        {
            _data = data;
            FileIconImage.Source = Helper.FileToImageConverter(Path.Combine(data.Destination, data.FileName));
            FileName.Content     = data.FileName;
            FileType.Content     = data.FileType;
            var destination       = data.Destination.Split('\\');
            var destinationString = "";
            var i = destination.Length;

            while (destinationString.Length < 30)
            {
                destinationString = destination[--i] + "\\" + destinationString;
            }

            Destination.Content = destinationString;

            timer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds(5)
            };
            timer.Tick += (s, args) => StartClose();
            timer.Start();
        }
        public void AddLog(MoveFileData data)
        {
            var entry = new FileLog(data);

            StackPanel.Children.Insert(0, entry);
        }
Esempio n. 9
0
        /// <summary>
        /// move a virtual cluster for a file to a logical cluster on disk, repeat for count clusters
        /// </summary>
        /// <param name="deviceName">device to move on"c:"</param>
        /// <param name="path">file to muck with "c:\windows\explorer.exe"</param>
        /// <param name="VCN">cluster number in file to move</param>
        /// <param name="LCN">cluster on disk to move to</param>
        /// <param name="count">for how many clusters</param>
        public static void MoveFile(string deviceName, string path, Int64 VCN, Int64 LCN, Int32 count)
        {
            IntPtr hVol = IntPtr.Zero;
            IntPtr hFile = IntPtr.Zero;
            try
            {
                hVol = OpenVolume(deviceName);

                hFile = OpenFile(path);

                MoveFileData mfd = new MoveFileData();
                mfd.hFile = hFile;
                mfd.StartingVCN = VCN;
                mfd.StartingLCN = LCN;
                mfd.ClusterCount = count;

                GCHandle handle = GCHandle.Alloc(mfd, GCHandleType.Pinned);
                uint bufSize = (uint)Marshal.SizeOf(mfd);

                IntPtr p = handle.AddrOfPinnedObject();
                uint size = 0;

                bool fResult = DeviceIoControl(
                    hVol,
                    FSConstants.FSCTL_MOVE_FILE,
                    p,
                    bufSize,
                    IntPtr.Zero, // no output data from this FSCTL
                    0,
                    ref size,
                    IntPtr.Zero);

                if (!fResult)
                {
                    Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                }
                handle.Free();
            }
            finally
            {
                CloseHandle(hVol);
                CloseHandle(hFile);
            }
        }
Esempio n. 10
0
 public void AddLog(MoveFileData data)
 {
     MoveFileLog.AddLog(data);
 }