#pragma warning disable CA1845, IDE0057
GetInferredCheckDirectory Process.Start for insiders vscode
This commit is contained in:
parent
38ab4424bc
commit
6783621dab
@ -2,6 +2,7 @@ using File_Folder_Helper.Helpers;
|
||||
using File_Folder_Helper.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
@ -187,7 +188,7 @@ internal static partial class Helper20240623
|
||||
" - Done",
|
||||
"---",
|
||||
string.Empty,
|
||||
$"# {h1}",
|
||||
h1[0] == '#' ? h1 : $"# {h1}",
|
||||
string.Empty,
|
||||
"## Backlog",
|
||||
string.Empty,
|
||||
@ -480,7 +481,7 @@ internal static partial class Helper20240623
|
||||
return result;
|
||||
}
|
||||
|
||||
private static bool FileWrite(Record record, List<string> newLines, double percent)
|
||||
private static bool FileWrite(long ticks, Record record, List<string> newLines, double percent)
|
||||
{
|
||||
bool result = false;
|
||||
if (record.StopLine is not null && record.SubTasksLine is not null)
|
||||
@ -488,7 +489,10 @@ internal static partial class Helper20240623
|
||||
string contents;
|
||||
string progressLine;
|
||||
List<string> resultLines;
|
||||
resultLines = record.LineNumber.Lines.ToList();
|
||||
if (record.FileInfo.LastWriteTime.Ticks <= ticks)
|
||||
resultLines = record.LineNumber.Lines.ToList();
|
||||
else
|
||||
resultLines = File.ReadAllLines(record.FileInfo.FullName).ToList();
|
||||
if (record.LineNumber.FrontMatterYamlEnd is not null)
|
||||
{
|
||||
progressLine = $"progress: {percent}";
|
||||
@ -532,17 +536,73 @@ internal static partial class Helper20240623
|
||||
return result;
|
||||
}
|
||||
|
||||
private static FileInfo GetIndexFileInfo(ILogger<Worker> logger, Input input, Record record, string codeInsidersLine)
|
||||
private static string? GetInferredCheckDirectory(string directory)
|
||||
{
|
||||
string? result = null;
|
||||
List<string> directoryNames = [];
|
||||
DirectoryInfo directoryInfo;
|
||||
string? checkDirectory = directory;
|
||||
directoryNames.Add(Path.GetFileName(checkDirectory));
|
||||
string pathRoot = Path.GetPathRoot(directory) ?? throw new Exception();
|
||||
for (int i = 0; i < directory.Length; i++)
|
||||
{
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory) || checkDirectory == pathRoot)
|
||||
break;
|
||||
directoryInfo = new(checkDirectory);
|
||||
if (!directoryInfo.Exists)
|
||||
directoryNames.Add(directoryInfo.Name);
|
||||
else
|
||||
{
|
||||
directoryNames.Reverse();
|
||||
result = string.IsNullOrEmpty(directoryInfo.LinkTarget) ? checkDirectory : directoryInfo.LinkTarget;
|
||||
for (int j = 0; j < directoryNames.Count; j++)
|
||||
result = Path.GetDirectoryName(result) ?? throw new Exception();
|
||||
foreach (string directoryName in directoryNames)
|
||||
result = Path.Combine(result, directoryName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void UpdateFileAndStartNewProcess(ILogger<Worker> logger, Input input, Record record, string inferredCheckDirectory)
|
||||
{
|
||||
if (record.CodeInsidersLine is null)
|
||||
throw new Exception();
|
||||
List<string> lines = record.LineNumber.Lines.ToList();
|
||||
lines[record.CodeInsidersLine.Value] = $"{input.CodeInsiders}{inferredCheckDirectory})";
|
||||
string text = string.Join(Environment.NewLine, lines);
|
||||
File.WriteAllText(record.FileInfo.FullName, text);
|
||||
record.FileInfo.Refresh();
|
||||
string file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "Microsoft VS Code Insiders", "Code - Insiders.exe");
|
||||
try
|
||||
{ _ = Process.Start(file, $"\"{inferredCheckDirectory}\""); }
|
||||
catch (Exception) { logger.LogWarning("Failed to start code-insiders!"); }
|
||||
}
|
||||
|
||||
private static FileInfo GetIndexFileInfo(ILogger<Worker> logger, Input input, Record record)
|
||||
{
|
||||
FileInfo result;
|
||||
string? indexFile;
|
||||
List<string> results;
|
||||
if (record.CodeInsidersLine is null)
|
||||
throw new Exception();
|
||||
string codeInsidersLine = record.LineNumber.Lines[record.CodeInsidersLine.Value];
|
||||
string raw = codeInsidersLine[input.CodeInsiders.Length..^1];
|
||||
string checkDirectory = $"{raw[..2].ToUpper()}{raw[2..]}";
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
{
|
||||
if (input.DestinationDirectories.Count > 0 && input.DestinationDirectories.Any(checkDirectory.Contains))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
{
|
||||
string? inferredCheckDirectory = GetInferredCheckDirectory(checkDirectory);
|
||||
if (!string.IsNullOrEmpty(inferredCheckDirectory))
|
||||
{
|
||||
checkDirectory = inferredCheckDirectory;
|
||||
_ = Directory.CreateDirectory(inferredCheckDirectory);
|
||||
UpdateFileAndStartNewProcess(logger, input, record, inferredCheckDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
results = [];
|
||||
@ -585,10 +645,10 @@ internal static partial class Helper20240623
|
||||
List<string> newLines;
|
||||
bool reloadAny = false;
|
||||
string? checkDirectory;
|
||||
string codeInsidersLine;
|
||||
List<string> oldLines = [];
|
||||
Input input = GetInput(args);
|
||||
string fileNameWithoutExtension;
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
ReadOnlyCollection<SubTaskLine> subTaskLines;
|
||||
for (int z = 0; z < 9; z++)
|
||||
{
|
||||
@ -607,12 +667,10 @@ internal static partial class Helper20240623
|
||||
}
|
||||
if (record.StopLine is null)
|
||||
continue;
|
||||
codeInsidersLine = record.LineNumber.Lines[record.CodeInsidersLine.Value];
|
||||
fileInfo = GetIndexFileInfo(logger, input, record, codeInsidersLine);
|
||||
fileInfo = GetIndexFileInfo(logger, input, record);
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
checkDirectory = codeInsidersLine[input.CodeInsiders.Length..^1];
|
||||
logger.LogError("<{checkDirectory}> doesn't have a [{indexFile}]", Path.GetFileName(checkDirectory), input.IndexFile);
|
||||
logger.LogError("<{checkDirectory}> doesn't have a [{indexFile}]", fileInfo.DirectoryName, input.IndexFile);
|
||||
continue;
|
||||
}
|
||||
oldLines.Clear();
|
||||
@ -664,7 +722,7 @@ internal static partial class Helper20240623
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
Thread.Sleep(500);
|
||||
Directory.Delete(checkDirectory);
|
||||
reload = FileWrite(record, newLines, percent);
|
||||
reload = FileWrite(ticks, record, newLines, percent);
|
||||
if (!reloadAny && reload)
|
||||
reloadAny = true;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ internal static partial class Helper20250306
|
||||
|
||||
private static string ProcessDataStandardFormatToJson(int columnsLine, string[] columns, string[] body)
|
||||
{
|
||||
#pragma warning disable CA1845, IDE0057
|
||||
string result = "[\n";
|
||||
string line;
|
||||
string value;
|
||||
@ -24,11 +25,12 @@ internal static partial class Helper20250306
|
||||
value = segments[c].Replace("\"", "\\\"").Replace("\\", "\\\\");
|
||||
line += '"' + columns[c].Trim('"') + '"' + ':' + '"' + value + '"' + ',';
|
||||
}
|
||||
line = line[..^1] + '}' + ',' + '\n';
|
||||
line = line.Substring(0, line.Length - 1) + '}' + ',' + '\n';
|
||||
result += line;
|
||||
}
|
||||
result = result[..^2] + ']';
|
||||
result = result.Substring(0, result.Length - 1) + ']';
|
||||
return result;
|
||||
#pragma warning restore CA1845, IDE0057
|
||||
}
|
||||
|
||||
private static void ProcessDataStandardFormatToJson(ILogger<Worker> logger, string file)
|
||||
|
Loading…
x
Reference in New Issue
Block a user