-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileUtils.cs
61 lines (49 loc) · 1.9 KB
/
FileUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.IO;
using System.Linq;
namespace ZuxiTags
{
internal class FileUtils
{
internal static string _VRCDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low\\VRChat\\VRChat";
internal static string LogFile = string.Empty;
public static string GetallTextFromLogFile()
{
// Open the file with the FileShare.ReadWrite option to allow reading while the file is open by another process
using (FileStream fileStream = new FileStream(LogFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (StreamReader reader = new StreamReader(fileStream))
{
// Read all text from the file
string fileText = reader.ReadToEnd();
return fileText;
}
}
public static void FindVRChatLatestFile()
{
try
{
// Get all files with ".txt" extension in the specified directory
var txtFiles = Directory.GetFiles(_VRCDirectory, "*.txt");
if (txtFiles.Length > 0)
{
// Sort files by creation time (descending) and select the first (most recent) file
string latestTxtFile = txtFiles.OrderByDescending(f => File.GetCreationTime(f)).First();
LogManager.Log("Latest .txt file: " + latestTxtFile);
LogFile = latestTxtFile;
}
else
{
LogManager.Log("No .txt files found in the directory.");
}
}
catch (DirectoryNotFoundException)
{
LogManager.Log("Directory not found.");
}
catch (Exception ex)
{
LogManager.Log("Error: " + ex.Message);
}
}
}
}