Skip to content

Commit 3f8f0dd

Browse files
committed
2 parents 985f6d6 + cbd5731 commit 3f8f0dd

21 files changed

Lines changed: 407 additions & 105 deletions

SaveWin10Pictures/Program.cs

Lines changed: 146 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.IO;
5+
using System.Reflection;
46

57
namespace SaveWin10Pictures
68
{
@@ -10,10 +12,13 @@ private static void Main()
1012
{
1113
Action<string> display = Console.WriteLine;
1214
Console.ForegroundColor = ConsoleColor.White;
15+
display($"Save Windows 10 wallpaper {DisplayTitle()} without Explorer opening");
16+
display(string.Empty);
1317
display("Checking if there are new images to be copied...");
1418
List<string> files = new List<string>();
1519
int counter = 0;
1620
//string OSVersion = Environment.OSVersion.ToString(); // 6.2 ON Win 10
21+
string OSVersion = GetOSInfo();
1722
//string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
1823
string userName = Environment.UserName;
1924
string userNameProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
@@ -22,7 +27,7 @@ private static void Main()
2227
// remove domain if any
2328
if (userName.Contains("\\"))
2429
{
25-
userName = userName.Split('\\')[1];
30+
userName = userName.Split('\\')[1];
2631
}
2732

2833
string imagePath = myPicturesFolder;
@@ -44,13 +49,24 @@ private static void Main()
4449

4550
try
4651
{
47-
const bool overwirte = false;
52+
//const bool overwrite = true;
53+
const bool doNotOverwrite = false;
4854
for (int i = 0; i < files.Count; i++)
4955
{
5056
string source = files[i];
51-
string destination = Path.Combine(imagePath, source) + ".jpg";
52-
File.Copy(source, destination, overwirte);
53-
counter++;
57+
string destination = Path.Combine(imagePath, Path.GetFileName(source)) + ".jpg";
58+
if (!File.Exists(destination))
59+
{
60+
File.Copy(source, destination, doNotOverwrite);
61+
counter++;
62+
// copying pic to source git
63+
string destinationGitPath = $@"C:\Users\{userName}\Source\Repos\SaveWindows10WallPaper\SaveWindows10WallPaper\images";
64+
string destinationGit = Path.Combine(destinationGitPath, Path.GetFileName(source)) + ".jpg";
65+
if (File.Exists(destinationGit))
66+
{
67+
File.Copy(source, destinationGit, doNotOverwrite);
68+
}
69+
}
5470
}
5571
}
5672
catch (Exception)
@@ -70,11 +86,52 @@ private static void Main()
7086
display(string.Empty);
7187
display($"{counter} image{Plural(counter)} {Plural(counter, "have")} been copied to the picture folder.");
7288
display(string.Empty);
89+
90+
// Open explorer to see source picture folder for test to debug
91+
//userName = Environment.UserName;
92+
//imagePath = $@"C:\Users\{userName}\Pictures";
93+
//if (Directory.Exists($@"C:\Users\{userName}\Pictures\fond_ecran"))
94+
//{
95+
// imagePath = $@"C:\Users\{userName}\Pictures\fond_ecran";
96+
//}
97+
98+
//StartProcess("Explorer.exe", imagePath, true, false);
99+
100+
// Open explorer to view target picture folder for test to debug
101+
//imagePath = $@"C:\Users\{userName}\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets";
102+
//if (Directory.Exists(imagePath))
103+
//{
104+
// StartProcess("Explorer.exe", imagePath, true, false);
105+
//}
106+
73107
Console.ForegroundColor = ConsoleColor.Yellow;
74108
display("Press any key to exit:");
75109
Console.ReadKey(); // comment for batch to production
76110
}
77111

112+
private static string DisplayTitle()
113+
{
114+
Assembly assembly = Assembly.GetExecutingAssembly();
115+
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
116+
return $@"V{fvi.FileMajorPart}.{fvi.FileMinorPart}.{fvi.FileBuildPart}.{fvi.FilePrivatePart}";
117+
}
118+
119+
public static void StartProcess(string dosScript, string arguments = "", bool useShellExecute = true, bool createNoWindow = false)
120+
{
121+
Process task = new Process
122+
{
123+
StartInfo =
124+
{
125+
UseShellExecute = useShellExecute,
126+
FileName = dosScript,
127+
Arguments = arguments,
128+
CreateNoWindow = createNoWindow
129+
}
130+
};
131+
132+
task.Start();
133+
}
134+
78135
public static string Plural(int number, string irregularNoun = "")
79136
{
80137
switch (irregularNoun)
@@ -187,5 +244,89 @@ public static List<string> GetFilesFileteredBySize(DirectoryInfo directoryInfo,
187244

188245
return result;
189246
}
247+
248+
public static string GetOSInfo()
249+
{
250+
//Get Operating system information.
251+
OperatingSystem os = Environment.OSVersion;
252+
//Get version information about the os.
253+
Version vs = os.Version;
254+
255+
//Variable to hold our return value
256+
string operatingSystem = "";
257+
258+
if (os.Platform == PlatformID.Win32Windows)
259+
{
260+
//This is a pre-NT version of Windows
261+
switch (vs.Minor)
262+
{
263+
case 0:
264+
operatingSystem = "95";
265+
break;
266+
case 10:
267+
if (vs.Revision.ToString() == "2222A")
268+
operatingSystem = "98SE";
269+
else
270+
operatingSystem = "98";
271+
break;
272+
case 90:
273+
operatingSystem = "Me";
274+
break;
275+
default:
276+
break;
277+
}
278+
}
279+
else if (os.Platform == PlatformID.Win32NT)
280+
{
281+
switch (vs.Major)
282+
{
283+
case 3:
284+
operatingSystem = "NT 3.51";
285+
break;
286+
case 4:
287+
operatingSystem = "NT 4.0";
288+
break;
289+
case 5:
290+
if (vs.Minor == 0)
291+
operatingSystem = "2000";
292+
else
293+
operatingSystem = "XP";
294+
break;
295+
case 6:
296+
if (vs.Minor == 0)
297+
operatingSystem = "Vista";
298+
else if (vs.Minor == 1)
299+
operatingSystem = "7";
300+
else if (vs.Minor == 2)
301+
operatingSystem = "8";
302+
else
303+
operatingSystem = "8.1";
304+
break;
305+
case 10:
306+
operatingSystem = "10";
307+
break;
308+
default:
309+
break;
310+
}
311+
}
312+
//Make sure we actually got something in our OS check
313+
//We don't want to just return " Service Pack 2" or " 32-bit"
314+
//That information is useless without the OS version.
315+
if (operatingSystem != "")
316+
{
317+
//Got something. Let's prepend "Windows" and get more info.
318+
operatingSystem = "Windows " + operatingSystem;
319+
//See if there's a service pack installed.
320+
if (os.ServicePack != "")
321+
{
322+
//Append it to the OS name. i.e. "Windows XP Service Pack 3"
323+
operatingSystem += " " + os.ServicePack;
324+
}
325+
//Append the OS architecture. i.e. "Windows XP Service Pack 3 32-bit"
326+
//operatingSystem += " " + getOSArchitecture().ToString() + "-bit";
327+
}
328+
//Return the information we've gathered.
329+
return operatingSystem;
330+
}
190331
}
191332
}

SaveWin10Pictures/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
3333
// en utilisant '*', comme indiqué ci-dessous :
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
35+
[assembly: AssemblyVersion("1.7.0.0")]
36+
[assembly: AssemblyFileVersion("1.7.0.0")]

SaveWin10Pictures/SaveWin10Pictures.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
<ErrorReport>prompt</ErrorReport>
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
35+
<PropertyGroup>
36+
<StartupObject>SaveWin10Pictures.Program</StartupObject>
37+
</PropertyGroup>
3538
<ItemGroup>
3639
<Reference Include="System" />
3740
<Reference Include="System.Core" />

0 commit comments

Comments
 (0)