Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions FileManager.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
Expand All @@ -14,9 +14,6 @@
<Content Include="Languages\*.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="links.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private void OpenLynkr_Click(object sender, RoutedEventArgs e)
private void OpenSettingsIni_Click(object sender, RoutedEventArgs e)
{
Logger.Log("Open Settings ini clicked");
var configPath = Path.Combine(AppContext.BaseDirectory, "dsfm.ini");
var configPath = Settings.ConfigPath;
try
{
Process.Start(new ProcessStartInfo("notepad.exe", configPath)
Expand Down
3 changes: 2 additions & 1 deletion Models/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using DamnSimpleFileManager.Utils;

namespace DamnSimpleFileManager
{
internal static class Settings
{
private static readonly string ConfigPath = Path.Combine(AppContext.BaseDirectory, "dsfm.ini");
internal static string ConfigPath => AppData.GetPath("dsfm.ini");
private static readonly Dictionary<string, string> Values = new();

public static bool ShowHiddenFiles =>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The application is intentionally minimalistic and aims to offer a straightforwar

## Configuration

`dsfm.ini` is created automatically next to the application.
`dsfm.ini` is stored per-user in the application's data folder (e.g., `%APPDATA%\\DamnSimpleFileManager`).
Set `hidden_files=false` to hide files and folders marked as hidden.
Set `copy_confirmation=false` to copy files and folders without confirmation.
Set `move_confirmation=false` to move files and folders without confirmation.
Expand Down
55 changes: 55 additions & 0 deletions Utils/AppData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;

namespace DamnSimpleFileManager.Utils
{
public static class AppData
{
public static readonly string DirectoryPath;

static AppData()
{
var basePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
DirectoryPath = Path.Combine(basePath, "DamnSimpleFileManager");
EnsureDirectory();
}

private static void EnsureDirectory()
{
if (Directory.Exists(DirectoryPath)) return;

var userSid = WindowsIdentity.GetCurrent().User!;
var security = new DirectorySecurity();
security.SetOwner(userSid);
security.AddAccessRule(new FileSystemAccessRule(
userSid,
FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow));

Directory.CreateDirectory(DirectoryPath, security);
}

public static string GetPath(string fileName)
{
var path = Path.Combine(DirectoryPath, fileName);
if (!File.Exists(path))
{
using (File.Create(path)) { }
var userSid = WindowsIdentity.GetCurrent().User!;
var security = new FileSecurity();
security.SetOwner(userSid);
security.AddAccessRule(new FileSystemAccessRule(
userSid,
FileSystemRights.FullControl,
AccessControlType.Allow));
File.SetAccessControl(path, security);
}
return path;
}
}
}

4 changes: 2 additions & 2 deletions Utils/LinkStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace DamnSimpleFileManager.Utils
{
public static class LinkStorage
{
private const string FileName = "links.json";
private static readonly string FileName = AppData.GetPath("links.json");

public static List<LinkItem> Load()
{
if (!File.Exists(FileName)) return new List<LinkItem>();
var json = File.ReadAllText(FileName);
if (string.IsNullOrWhiteSpace(json)) return new List<LinkItem>();
return JsonSerializer.Deserialize<List<LinkItem>>(json) ?? new List<LinkItem>();
}

Expand Down
1 change: 0 additions & 1 deletion links.json

This file was deleted.