AOT Compiling Switched to Secret from Development json file Added Kanbn Humanizer HelperCreateNoteFiles.CleanExistingFiles HelperPackageFilesByDate Added SRP Helper Hardcoded File Search and Sort Set Date from Zip Entry
100 lines
4.0 KiB
C#
100 lines
4.0 KiB
C#
using System.Globalization;
|
|
|
|
namespace File_Folder_Helper.Helpers;
|
|
|
|
internal static class HelperCreateNoteFiles
|
|
{
|
|
|
|
private static void CleanExistingFiles(string directory, long ticks)
|
|
{
|
|
string check;
|
|
string[] lines;
|
|
string checkFile;
|
|
string? fileDirectory;
|
|
string checkDirectory;
|
|
bool circularReference;
|
|
string fileNameWithoutExtension;
|
|
char altDrive = directory[0] is 'c' or 'C' ? 'D' : 'C';
|
|
string[] files = Directory.GetFiles(directory, "*.md", SearchOption.AllDirectories);
|
|
string match = ",*** *** *** *** *** *** *** *** ***,*** *** *** *** *** *** *** *** ***,*** *** *** *** *** *** *** *** ***,,TODO:,*** *** *** *** *** *** *** *** ***,*** *** *** *** *** *** *** *** ***,,Notes:,*** *** *** *** *** *** *** *** ***,*** *** *** *** *** *** *** *** ***";
|
|
foreach (string file in files)
|
|
{
|
|
lines = File.ReadAllLines(file);
|
|
if (lines.Length < 1)
|
|
continue;
|
|
circularReference = false;
|
|
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
|
|
for (int i = 0; i < lines.Length; i++)
|
|
{
|
|
if (!lines[i].Contains($"[[{fileNameWithoutExtension}]]"))
|
|
continue;
|
|
lines[i] = lines[i].Replace("[[", "__").Replace("]]", "__");
|
|
if (!circularReference)
|
|
circularReference = true;
|
|
}
|
|
if (circularReference)
|
|
File.WriteAllLines(file, lines);
|
|
lines[0] = string.Empty;
|
|
check = string.Join(',', lines);
|
|
if (check != match)
|
|
continue;
|
|
fileDirectory = Path.GetDirectoryName(file);
|
|
if (string.IsNullOrEmpty(fileDirectory))
|
|
continue;
|
|
checkDirectory = $"{altDrive}:/{ticks}/{fileDirectory[3..]}";
|
|
if (!Directory.Exists(checkDirectory))
|
|
_ = Directory.CreateDirectory(checkDirectory);
|
|
checkFile = $"{altDrive}:/{ticks}/{file[3..]}";
|
|
if (File.Exists(checkFile))
|
|
continue;
|
|
File.Move(file, checkFile);
|
|
}
|
|
_ = HelperDeleteEmptyDirectories.DeleteEmptyDirectories(directory);
|
|
}
|
|
|
|
internal static void CreateNoteFiles(string argsZero)
|
|
{
|
|
string file;
|
|
string directory;
|
|
string weekOfYear;
|
|
DateTime dateTime;
|
|
long ticks = DateTime.Now.Ticks;
|
|
CleanExistingFiles(argsZero, ticks);
|
|
string lastDirectory = string.Empty;
|
|
DateTime startDateTime = DateTime.Now.AddDays(1);
|
|
Calendar calendar = new CultureInfo("en-US").Calendar;
|
|
double totalDays = new TimeSpan(DateTime.Now.AddDays(1000).Ticks - startDateTime.Ticks).TotalDays;
|
|
int days = (int)Math.Ceiling(totalDays);
|
|
for (int i = 0; i < days; i++)
|
|
{
|
|
dateTime = startDateTime.AddDays(i);
|
|
weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
|
directory = Path.Combine(argsZero, ticks.ToString(), dateTime.ToString("yyyy"), $"Week_{weekOfYear}");
|
|
if (!Directory.Exists(directory))
|
|
_ = Directory.CreateDirectory(directory);
|
|
file = string.Concat(Path.Combine(directory, $"{dateTime:yyyy-MM-dd}.md"));
|
|
if (File.Exists(file))
|
|
continue;
|
|
File.WriteAllLines(file, new string[]
|
|
{
|
|
"---",
|
|
"type: daily-note",
|
|
$"created: {dateTime:yyyy-MM-dd}",
|
|
"---",
|
|
string.Empty,
|
|
$"# {dateTime:yyyy-MM-dd dddd}",
|
|
string.Empty,
|
|
"```bash",
|
|
string.Empty,
|
|
"```",
|
|
});
|
|
if (directory != lastDirectory)
|
|
{
|
|
Directory.SetCreationTime(directory, dateTime);
|
|
Directory.SetLastWriteTime(directory, dateTime);
|
|
}
|
|
lastDirectory = directory;
|
|
}
|
|
}
|
|
|
|
} |