-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
80 lines (72 loc) · 2.71 KB
/
Program.cs
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
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Wallsh
{
class Program
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern Int32 SystemParametersInfo(UInt32 uiAction, int uParam, String pvParam, UInt32 fWinIni);
private static UInt32 SPI_GETDESKWALLPAPER = 0x73;
private static UInt32 SPI_SETDESKWALLPAPER = 20;
private static int MAX_PATH = 260;
private static UInt32 SPIF_UPDATEINIFILE = 0x1;
static void Main(string[] args)
{
if(args.Length > 0)
switch (args[0])
{
case "/G":
getWallpaper();
break;
case "/S":
if (args.Length == 2)
setWallpaper(args[1]);
else {
Console.Write("No path introduced!");
Environment.Exit(1);
}
break;
default:
printHelp();
break;
}
else printHelp();
}
private static void getWallpaper()
{
string currentWallpaper = new string('\0', MAX_PATH);
SystemParametersInfo(SPI_GETDESKWALLPAPER, currentWallpaper.Length, currentWallpaper, 0);
Console.Write(currentWallpaper.Substring(0, currentWallpaper.IndexOf('\0')));
}
private static void setWallpaper(string filename)
{
if (File.Exists(filename))
{
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename, SPIF_UPDATEINIFILE);
Registry.SetValue(@"HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", filename);
}
else{
Console.Write("Invalid path introduced!");
Environment.Exit(1);
}
}
private static void printHelp()
{
string message =
"\r\n wallsh (v0.1): get and set the desktop wallpaper." +
"\r\n\r\n Usage:\twallsh [options]" +
"\r\n\r\n Options:" +
"\r\n /H \t\t\tprint help" +
"\r\n /G \t\t\tget the current wallpaper" +
"\r\n /S [path]\t\t\tset a wallpaper" +
"\r\n\r\n Created by Jaume Segarra";
Console.Write(message);
}
}
}