@@ -22,13 +22,26 @@ class Program
22
22
public static extern Int32 SystemParametersInfo ( UInt32 uiAction , UInt32 uiParam , String pvParam , UInt32 fWinIni ) ;
23
23
public static UInt32 SPI_SETDESKWALLPAPER = 20 ;
24
24
public static UInt32 SPIF_UPDATEINIFILE = 0x1 ;
25
+ /// <summary>
26
+ /// portable lively build, no installer.
27
+ /// </summary>
28
+ public static readonly bool isPortableBuild = false ;
29
+ public static string PathData { get ; private set ; }
25
30
26
31
static void Main ( string [ ] args )
27
32
{
28
33
34
+ if ( isPortableBuild )
35
+ {
36
+ PathData = AppDomain . CurrentDomain . BaseDirectory ;
37
+ }
38
+ else
39
+ {
40
+ PathData = Path . Combine ( System . Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) , "Lively Wallpaper" ) ;
41
+ }
42
+
29
43
int livelyId ;
30
44
Process lively ;
31
-
32
45
if ( args . Length == 0 )
33
46
{
34
47
Console . WriteLine ( "NO arguments sent." ) ;
@@ -76,7 +89,7 @@ static void Main(string[] args)
76
89
77
90
lively . WaitForExit ( ) ;
78
91
79
- Console . WriteLine ( "done waiting, ready to kill *_* " ) ;
92
+ Console . WriteLine ( "done waiting, ready to kill.. " ) ;
80
93
//Console.Read();
81
94
82
95
FileHandle . LoadRunningPrograms ( ) ;
@@ -86,8 +99,9 @@ static void Main(string[] args)
86
99
Console . WriteLine ( "pgm list:- " + proc . ProcessName + " " + proc . MainWindowHandle ) ;
87
100
foreach ( var wproc in FileHandle . runningPrograms )
88
101
{
102
+ //Pid + Process-name is unique enough to make sure its the correct pgm.
89
103
if ( proc . ProcessName . Equals ( wproc . ProcessName , StringComparison . OrdinalIgnoreCase ) && proc . Id == wproc . Pid ) //&& IntPtr.Equals(proc.MainWindowHandle,wproc.handle))//proc.Handle == wproc.handle)
90
- {
104
+ {
91
105
Console . WriteLine ( "Unclosed pgm, kill:- " + proc . ProcessName ) ;
92
106
try
93
107
{
@@ -122,7 +136,7 @@ public RunningProgram()
122
136
}
123
137
124
138
public static List < RunningProgram > runningPrograms = new List < RunningProgram > ( ) ;
125
- private static string pathData = Path . Combine ( System . Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) , "LivelyWallpaper " ) ;
139
+ // private static string pathData = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Lively Wallpaper ");
126
140
127
141
public class RunningProgramsList
128
142
{
@@ -131,26 +145,19 @@ public class RunningProgramsList
131
145
132
146
public static void LoadRunningPrograms ( )
133
147
{
134
- if ( ! File . Exists ( Path . Combine ( pathData , "lively_running_pgms.json" ) ) )
135
- {
136
- return ;
137
- }
138
-
139
148
try
140
149
{
141
-
142
150
// deserialize JSON directly from a file
143
- using ( StreamReader file = File . OpenText ( Path . Combine ( pathData , "lively_running_pgms.json" ) ) )
151
+ using ( StreamReader file = File . OpenText ( Path . Combine ( Program . PathData , "lively_running_pgms.json" ) ) )
144
152
{
145
153
JsonSerializer serializer = new JsonSerializer ( ) ;
146
154
RunningProgramsList tmp = ( RunningProgramsList ) serializer . Deserialize ( file , typeof ( RunningProgramsList ) ) ;
147
155
runningPrograms = tmp . Item ;
148
156
}
149
-
150
157
}
151
- catch ( Exception e )
158
+ catch
152
159
{
153
- System . Diagnostics . Debug . WriteLine ( e . Message + " " + e . StackTrace ) ;
160
+ Debug . WriteLine ( "failed to read json" ) ;
154
161
}
155
162
}
156
163
@@ -170,10 +177,17 @@ public static void SaveRunningPrograms()
170
177
NullValueHandling = NullValueHandling . Include
171
178
} ;
172
179
173
- using ( StreamWriter sw = new StreamWriter ( Path . Combine ( pathData , "\\ lively_running_pgms.json" ) ) )
174
- using ( JsonWriter writer = new JsonTextWriter ( sw ) )
180
+ try
181
+ {
182
+ using ( StreamWriter sw = new StreamWriter ( Path . Combine ( Program . PathData , "lively_running_pgms.json" ) ) )
183
+ using ( JsonWriter writer = new JsonTextWriter ( sw ) )
184
+ {
185
+ serializer . Serialize ( writer , tmp ) ;
186
+ }
187
+ }
188
+ catch
175
189
{
176
- serializer . Serialize ( writer , tmp ) ;
190
+ Debug . WriteLine ( "failed to write json" ) ;
177
191
}
178
192
}
179
193
0 commit comments