-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectoryTreeGenerator.linq
More file actions
201 lines (184 loc) · 5.15 KB
/
DirectoryTreeGenerator.linq
File metadata and controls
201 lines (184 loc) · 5.15 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<Query Kind="Program" />
public class DirectoryTreeGenerator
{
public class TreeNode
{
public string Name { get; set; }
public string Comment { get; set; }
public bool IsFile { get; set; }
public List<TreeNode> Children { get; set; }
public TreeNode(string name, string comment = "", bool isFile = false)
{
Name = name;
Comment = comment;
IsFile = isFile;
Children = new List<TreeNode>();
}
}
public void GenerateFromText(string treeText, string baseDirectory)
{
var lines = treeText.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
var root = ParseTreeText(lines);
CreateDirectoryStructure(root, baseDirectory);
}
private TreeNode ParseTreeText(string[] lines)
{
var root = new TreeNode("root");
var currentPath = new Stack<TreeNode>();
currentPath.Push(root);
int previousIndentLevel = -1;
foreach (var line in lines)
{
if (string.IsNullOrWhiteSpace(line)) continue;
var indentMatch = Regex.Match(line, @"^[\s│├└─]*");
int currentIndentLevel = indentMatch.Length;
// Adjust stack based on indent level
while (currentPath.Count > 1 && previousIndentLevel >= currentIndentLevel)
{
currentPath.Pop();
previousIndentLevel -= 2;
}
// Parse the line
var cleanLine = line.TrimStart(' ', '│', '├', '└', '─');
var parts = cleanLine.Split(new[] { '#' }, 2);
var name = parts[0].Trim();
var comment = parts.Length > 1 ? parts[1].Trim() : "";
// Create node
var node = new TreeNode(name, comment, !name.EndsWith("/"));
currentPath.Peek().Children.Add(node);
if (!node.IsFile)
{
currentPath.Push(node);
previousIndentLevel = currentIndentLevel;
}
}
return root;
}
private void CreateDirectoryStructure(TreeNode node, string currentPath)
{
foreach (var child in node.Children)
{
var newPath = Path.Combine(currentPath, child.Name);
try
{
if (child.IsFile)
{
if (!File.Exists(newPath))
{
File.Create(newPath).Close();
Console.WriteLine($"Created file: {newPath}");
// If there's a comment, add it as first line in the file
if (!string.IsNullOrEmpty(child.Comment))
{
File.WriteAllText(newPath, $"// {child.Comment}\n");
}
}
else
{
Console.WriteLine($"File already exists: {newPath}");
}
}
else
{
if (!Directory.Exists(newPath))
{
Directory.CreateDirectory(newPath);
Console.WriteLine($"Created directory: {newPath}");
}
CreateDirectoryStructure(child, newPath);
}
}
catch (Exception ex)
{
Console.WriteLine($"Error creating {(child.IsFile ? "file" : "directory")} {newPath}: {ex.Message}");
}
}
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter base directory name:");
//string baseDir = Util.ReadLine();
string baseDir = args.Any() ? args[0] : Console.ReadLine();
//Console.WriteLine("Enter tree structure (press Ctrl+Z on Windows or Ctrl+D on Unix and Enter when done):");
string treeText = args.Length > 1 ? args[1] :
"""
Tetris3D/
├── .gitignore
├── CMakeLists.txt
├── README.md
├── LICENSE
│
├── src/ # Source files
│ ├── main.cpp
│ ├── Game.cpp
│ ├── Graphics.cpp
│ ├── Audio.cpp
│ ├── Input.cpp
│ ├── UI.cpp
│ ├── ParticleSystem.cpp
│ ├── Camera.cpp
│ ├── DebugRenderer.cpp
│ └── ProfilerSystem.cpp
│
├── include/ # Header files
│ ├── Game.h
│ ├── Graphics.h
│ ├── Audio.h
│ ├── Input.h
│ ├── UI.h
│ ├── ParticleSystem.h
│ ├── Camera.h
│ ├── DebugRenderer.h
│ └── ProfilerSystem.h
│
├── shaders/ # HLSL shader files
│ ├── VertexShader.hlsl
│ ├── PixelShader.hlsl
│ └── ParticleShader.hlsl
│
├── assets/ # Game assets
│ ├── textures/
│ ├── sounds/
│ ├── fonts/
│ └── models/
│
├── tests/ # Test files
│ ├── CMakeLists.txt
│ ├── TestGame.cpp
│ ├── TestGraphics.cpp
│ └── TestAudio.cpp
│
├── docs/ # Documentation
│ ├── api/
│ ├── design/
│ └── README.md
│
├── scripts/ # Build/deployment scripts
│ ├── build.bat
│ ├── package.bat
│ └── deploy.bat
│
├── extern/ # External dependencies
│ └── README.md
│
└── build/ # Build output (git ignored)
├── bin/
├── lib/
└── obj/
"""
;
DirectoryTreeGenerator generator = new DirectoryTreeGenerator();
try
{
generator.GenerateFromText(treeText, baseDir);
Console.WriteLine("\nDirectory structure created successfully!");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}