Skip to content

Commit c82cf53

Browse files
committed
Save locations in user's roaming folder to enable write access
1 parent 7b4f230 commit c82cf53

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

GrabWindows10LockScreenPictures/Data/locations.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

GrabWindows10LockScreenPictures/GrabWindows10LockScreenPictures.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
@@ -13,7 +13,6 @@
1313
<None Remove="Data\lion.png" />
1414
<None Remove="Data\lionicon.ico" />
1515
<None Remove="Data\lion_icon.ico" />
16-
<None Remove="Data\locations.txt" />
1716
</ItemGroup>
1817

1918
<ItemGroup>
@@ -37,9 +36,6 @@
3736
<Resource Include="Data\lionicon.ico">
3837
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
3938
</Resource>
40-
<Content Include="Data\locations.txt">
41-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
42-
</Content>
4339
</ItemGroup>
4440

4541
</Project>

GrabWindows10LockScreenPictures/Program.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,28 @@
66

77
namespace GrabWindows10LockScreenPictures {
88
class Program {
9+
static readonly string App_Folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Grab Windows 10 Lock Screen Pictures";
910
static void Main(string[] args) {
10-
string[] users = File.ReadAllLines(Path.GetFullPath("Data/locations.txt"));
11-
string saved = @$"C:\Users\{users.FirstOrDefault()}\Pictures\Spotlight Images";
12-
1311
try {
14-
foreach (string name in users) {
15-
GetPics(@$"C:\Users\{name}\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets", saved);
12+
string userName = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile).Replace(@"C:\Users\", "");
13+
14+
if (!Directory.Exists(App_Folder)) {
15+
Directory.CreateDirectory(App_Folder);
16+
File.WriteAllText(Path.Combine(App_Folder, "locations.txt"), userName);
1617
}
1718

18-
PopTheToast.PopIt("All images were successfully saved.");
19+
if (File.Exists(Path.Combine(App_Folder, "locations.txt"))) {
20+
string[] users = File.ReadAllLines(Path.Combine(App_Folder, "locations.txt"));
21+
string saved = @$"C:\Users\{users.FirstOrDefault()}\Pictures\Spotlight Images";
22+
23+
foreach (string name in users) {
24+
GetPics(@$"C:\Users\{name}\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets", saved);
25+
}
26+
27+
PopTheToast.PopIt("All images were successfully saved.");
28+
} else {
29+
PopTheToast.PopIt("Error: locations.txt file was not found.");
30+
}
1931
} catch (Exception ex) {
2032
PopTheToast.PopIt("An error occurred: " + ex.Message);
2133
}

0 commit comments

Comments
 (0)