コード例 #1
0
 private static string MakeChangesContent(string logContent)
 {
     return(string.Format("({0:+#;-#;0}byte(s)) ", DigdaLog.GetAddSize(logContent))
            + DigdaLog.GetFileName(logContent));
 }
コード例 #2
0
        private static void WriteChanges(string logPath, int depth)
        {
            RemoveLogContent(DigChangeLogPath, Path.GetFileName(logPath));

            Console.WriteLine($"[Debug] {logPath}");
            List <string> log     = ReadLog(logPath);
            List <string> deleted = ReadLog(DeletedFilesLogPath);

            int last = log.Count - 1;

            if (last < 0)
            {
                Console.WriteLine("log is empty, writing failed...");
                return;
            }

            if (DigdaLog.GetAddSize(log[last]) == 0)
            {
                return;
            }
            else if (DigdaLog.GetAddSize(log[last]) == DigdaLog.GetSize(log[last]))
            {
                changesHolder.Add(GetSpaces(depth) + "[Created] " + MakeChangesContent(log[last]));
            }
            else
            {
                changesHolder.Add(GetSpaces(depth) + "[Changed] " + MakeChangesContent(log[last]));
            }

            foreach (string s in deleted)
            {
                string[] split          = s.Split('|');
                string   tmpLogFilePath = DigdaLog.GetLogFilePath(Path.GetDirectoryName(split[0]));
                long     size           = long.Parse(split[1]);

                if (tmpLogFilePath.Equals(logPath))
                {
                    changesHolder.Add(GetSpaces(depth + 1) + "[Deleted] " + string.Format("({0:+#;-#;0}byte(s)) ", size * -1) + Path.GetFileName(split[0]));
                    RemoveLogContent(DeletedFilesLogPath, s);
                }
            }

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

            foreach (string s in log)
            {
                string tmp = s;
                if (DigdaLog.GetAddSize(s) != 0)
                {
                    string status = null;

                    if (DigdaLog.GetSize(s) == DigdaLog.GetAddSize(s))
                    {
                        status = "[Created] ";
                    }
                    else
                    {
                        status = "[Changed] ";
                    }

                    switch (DigdaLog.GetFileType(s))
                    {
                    case FileType.File:
                        changesHolder.Add(GetSpaces(depth + 1) + status + MakeChangesContent(s));
                        break;

                    case FileType.Directory:
                        string tmpLogPath = logPath.Remove(logPath.Length - 4) + '@' + DigdaLog.GetFileName(s) + ".dig";
                        WriteChanges(tmpLogPath, depth + 1);
                        break;

                    case FileType.This:
                        break;
                    }

                    tmp = DigdaLog.SetAddSize(tmp, 0);
                }
                writer.WriteLine(tmp);
            }

            writer.Close();
        }