Пример #1
0
        public static void DeleteLogContent(string fileFullPath)
        {
            string path     = GetLogFilePath(Path.GetDirectoryName(fileFullPath));
            string fileName = Path.GetFileName(fileFullPath);

            List <string> list = ReadLogFile(path);
            int           last = list.Count - 1;

            if (last < 0)
            {
                WriteEmptyFolderLog(Path.GetDirectoryName(fileFullPath), path);
                list = ReadLogFile(path);
                last = list.Count - 1;
            }

            StreamWriter writer = Digda.WaitAndGetWriter(path, FileMode.Create);

            long removeSize = 0;

            for (int i = 0; i < list.Count - 1; i++)
            {
                if (GetFileName(list[i]).Equals(fileName))
                {
                    removeSize = -1 * GetSize(list[i]);
                    list[last] = AddSizeToBoth(list[last], removeSize);

                    long sizeDiff = GetSize(list[i]) - GetAddSize(list[i]);
                    if (sizeDiff > 0)
                    {
                        DigdaSysLog.InsertLogContent(DigdaSysLog.DeletedFilesLogPath, fileFullPath + '|' + sizeDiff);
                    }
                    continue;
                }
                writer.WriteLine(list[i]);
            }
            writer.WriteLine(list[last]);

            writer.Close();

            if (File.Exists(GetLogFilePath(fileFullPath)))
            {
                DeleteLogAndChilds(fileFullPath);
            }

            if (removeSize != 0)
            {
                UpdateParentLog(Path.GetDirectoryName(fileFullPath), GetSize(list[last]));
            }

            DigdaSysLog.InsertLogContent(DigdaSysLog.DigChangeLogPath, Path.GetFileName(path));
        }
Пример #2
0
        public static void ChangeLogContent(string fullPath, long size)
        {
            string path = GetLogFilePath(Path.GetDirectoryName(fullPath));

            List <string> list = ReadLogFile(path);
            int           last = list.Count - 1;

            if (last < 0)
            {
                WriteEmptyFolderLog(Path.GetDirectoryName(fullPath), path);
                list = ReadLogFile(path);
                last = list.Count - 1;
            }

            StreamWriter writer = Digda.WaitAndGetWriter(path, FileMode.Create);

            long diff = 0;

            for (int i = 0; i < list.Count - 1; i++)
            {
                if (GetFileName(list[i]).Equals(Path.GetFileName(fullPath)))
                {
                    diff = size - GetSize(list[i]);
                    string content = File.Exists(fullPath) ? MakeFileInfos(fullPath, size, diff) : MakeDirectoryInfos(fullPath, size, diff);
                    content = AddSizeToAddSize(content, GetAddSize(list[i]));
                    writer.WriteLine(content);

                    list[last] = AddSizeToBoth(list[last], diff);
                    continue;
                }
                writer.WriteLine(list[i]);
            }
            writer.WriteLine(list[last]);

            writer.Close();

            if (diff != 0)
            {
                UpdateParentLog(Path.GetDirectoryName(fullPath), GetSize(list[last]));
            }

            DigdaSysLog.InsertLogContent(DigdaSysLog.DigChangeLogPath, Path.GetFileName(path));
        }
Пример #3
0
        public static void AddLogContent(string fileFullPath)
        {
            string path = GetLogFilePath(Path.GetDirectoryName(fileFullPath));

            if (File.Exists(path) == false)
            {
                WriteEmptyFolderLog(Path.GetDirectoryName(fileFullPath), path);
            }

            string content = null;

            try
            {
                if (File.Exists(fileFullPath))
                {
                    FileInfo file = new FileInfo(fileFullPath);
                    content = MakeFileInfos(file, file.Length);
                }
                else if (Directory.Exists(fileFullPath))
                {
                    DirectoryInfo dir  = new DirectoryInfo(fileFullPath);
                    long          size = Digda.GetDirectorySize(dir, 0);
                    content = MakeDirectoryInfos(dir, size, size);
                }
                else
                {
                    return;
                }
            }
            catch (System.UnauthorizedAccessException)
            {
                return;
            }
            catch (FileNotFoundException)
            {
                return;
            }

            List <string> list = ReadLogFile(path);
            int           last = list.Count - 1;

            long diff = GetSize(content);

            if (diff != 0)
            {
                list[last] = AddSizeToBoth(list[last], diff);
            }

            StreamWriter writer = Digda.WaitAndGetWriter(path, FileMode.Create);

            bool isWritten = false;

            for (int i = 0; i < list.Count; i++)
            {
                if (isWritten == false && FileInfoCompare(content, list[i]) < 0)
                {
                    writer.WriteLine(content);
                    isWritten = true;
                }
                writer.WriteLine(list[i]);
            }

            writer.Close();

            if (diff != 0)
            {
                UpdateParentLog(Path.GetDirectoryName(fileFullPath), GetSize(list[last]));
            }

            DigdaSysLog.InsertLogContent(DigdaSysLog.DigChangeLogPath, Path.GetFileName(path));
        }