Skip to content

Commit 9016059

Browse files
New Avalonia.UI based desktop app
1 parent 33cb0a7 commit 9016059

25 files changed

+1343
-326
lines changed

.gitignore

Lines changed: 447 additions & 13 deletions
Large diffs are not rendered by default.

Directory.Build.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<PropertyGroup>
3+
<Nullable>enable</Nullable>
4+
<AvaloniaVersion>11.1.0</AvaloniaVersion>
5+
</PropertyGroup>
6+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>WinExe</OutputType>
4+
<!--If you are willing to use Windows/MacOS native APIs you will need to create 3 projects.
5+
One for Windows with net8.0-windows TFM, one for MacOS with net8.0-macos and one with net8.0 TFM for Linux.-->
6+
<TargetFramework>net8.0</TargetFramework>
7+
<Nullable>enable</Nullable>
8+
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
9+
<ApplicationManifest>app.manifest</ApplicationManifest>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\FileHider\FileHider.csproj" />
18+
</ItemGroup>
19+
</Project>

FileHider.Desktop/Program.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
3+
using Avalonia;
4+
5+
namespace FileHider.Desktop;
6+
7+
class Program
8+
{
9+
// Initialization code. Don't use any Avalonia, third-party APIs or any
10+
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
11+
// yet and stuff might break.
12+
[STAThread]
13+
public static void Main(string[] args) => BuildAvaloniaApp()
14+
.StartWithClassicDesktopLifetime(args);
15+
16+
// Avalonia configuration, don't remove; also used by visual designer.
17+
public static AppBuilder BuildAvaloniaApp()
18+
=> AppBuilder.Configure<App>()
19+
.UsePlatformDetect()
20+
.WithInterFont()
21+
.LogToTrace();
22+
23+
}

FileHider.Desktop/app.manifest

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<!-- This manifest is used on Windows only.
4+
Don't remove it as it might cause problems with window transparency and embeded controls.
5+
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
6+
<assemblyIdentity version="1.0.0.0" name="AvaloniaTest.Desktop"/>
7+
8+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
9+
<application>
10+
<!-- A list of the Windows versions that this application has been tested on
11+
and is designed to work with. Uncomment the appropriate elements
12+
and Windows will automatically select the most compatible environment. -->
13+
14+
<!-- Windows 10 -->
15+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
16+
</application>
17+
</compatibility>
18+
</assembly>

FileHider.Lib/DirectoryNode.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using FileHider.Lib.FilesList;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Collections.ObjectModel;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace FileHider.Lib.FilesList;
10+
11+
public class DirectoryNode : INode
12+
{
13+
public string Name { get; }
14+
public DirectoryNode? ParentDirectory { get; }
15+
16+
static private DirectoryNode _root = new DirectoryNode("", null);
17+
static public DirectoryNode RootDir { get { return _root; } }
18+
public ObservableCollection<INode> Children { get; }
19+
20+
private DirectoryNode(string name, DirectoryNode? parent)
21+
{
22+
Name = name;
23+
ParentDirectory = parent;
24+
Children = new();
25+
if (parent != null)
26+
{
27+
parent.AddChild(this);
28+
}
29+
}
30+
31+
/// <summary>
32+
/// Creates a new `DirectoryNode`.
33+
/// </summary>
34+
/// <param name="name">Name of the directory</param>
35+
/// <param name="parent">Parent directory</param>
36+
/// <returns>A new DirectoryNode</returns>
37+
public static DirectoryNode Create(string name, DirectoryNode parent)
38+
{
39+
return new(name, parent);
40+
}
41+
42+
/// <summary>
43+
/// Returns the virtual realPath to the inside of the parent.
44+
/// </summary>
45+
/// <returns>`string`: Virtual realPath to the inside of the parent.</returns>
46+
public string GetVirtualPath() => (ParentDirectory == null) ? Name : Path.Combine(ParentDirectory.GetVirtualPath(), Name);
47+
48+
/// <summary>
49+
/// Deletes all children inside the parent.
50+
/// </summary>
51+
public void Delete()
52+
{
53+
foreach (var child in Children)
54+
{
55+
child.Delete();
56+
}
57+
Children.Clear();
58+
}
59+
60+
public void DeleteItem(INode item)
61+
{
62+
Children.Remove(item);
63+
}
64+
65+
public void AddChild(INode item)
66+
{
67+
Children.Add(item);
68+
}
69+
}

FileHider.Lib/FileNode.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace FileHider.Lib.FilesList;
8+
9+
public class FileNode : INode
10+
{
11+
public string Name { get; }
12+
public string RealPath { get; }
13+
public DirectoryNode ParentDirectory { get; }
14+
15+
private FileNode(string realPath, DirectoryNode parent)
16+
{
17+
RealPath = Path.GetFullPath(realPath);
18+
Name = Path.GetFileName(realPath);
19+
ParentDirectory = parent;
20+
parent.AddChild(this);
21+
}
22+
23+
public static FileNode Create(string realPath, DirectoryNode parent) => new(realPath, parent);
24+
25+
/// <summary>
26+
/// Returns the virtual realPath to the file.
27+
/// </summary>
28+
/// <returns>`string`: Virtual realPath to the file.</returns>
29+
public string GetVirtualPath() => Path.Combine(ParentDirectory.GetVirtualPath(), Name);
30+
31+
/// <summary>
32+
/// Deletes the file (does nothing on a file).
33+
/// </summary>
34+
public void Delete()
35+
{
36+
}
37+
}

0 commit comments

Comments
 (0)