Skip to content

Commit c52d500

Browse files
authored
Merge pull request #17 from tomasrudh/iG8R-Changes
Ig8r changes
2 parents b315e55 + cb0f928 commit c52d500

14 files changed

+313
-150
lines changed

ClsCurrentWindows.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public ClsWindowProps GetWindowProperties(long hWnd)
187187
/// <param name="SavedWindow">The window to use for location</param>
188188
/// <param name=""></param>
189189
//**********************************************
190-
public void MoveCurrentWindow(int currentWindowIndex, ClsWindowProps savedWindowProps, int savedWindowIndex, ClsScreenList savedScreenProps, ClsScreenList currentScreenProps)
190+
public void MoveCurrentWindow(int currentWindowIndex, ClsWindowProps savedWindowProps, int savedWindowIndex, ClsScreenList savedScreenProps, ClsScreenList currentScreenProps, string dataPath)
191191
{
192192
try
193193
{
@@ -239,7 +239,7 @@ public void MoveCurrentWindow(int currentWindowIndex, ClsWindowProps savedWindow
239239

240240
if (Return == false)
241241
{
242-
ClsDebug.LogNow("Window could not be moved: " + savedWindowProps.Name);
242+
ClsDebug.LogNow(dataPath, "Window could not be moved: " + savedWindowProps.Name);
243243
ClsDebug.LogToEvent(new Exception(""), EventLogEntryType.Error, " Window could not be moved: " + savedWindowProps.Name);
244244
}
245245
}
@@ -270,13 +270,13 @@ public struct POINT
270270
public int y;
271271
}
272272

273-
public void ResetMoved()
273+
public void ResetMoved(string dataPath)
274274
{
275275
foreach (ClsWindows Win in this.Windows)
276276
{
277277
Win.Moved = false;
278278
}
279-
ClsDebug.LogNow("ResetMoved\n");
279+
ClsDebug.LogNow(dataPath, "ResetMoved\n");
280280
}
281281

282282
//**********************************************

ClsDebug.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
namespace WinSize4
66
{
7-
public static class ClsDebug
7+
public class ClsDebug
88
{
99
public static bool Debug = false;
1010
public static string _text = "";
1111

12-
public static void ClearLog()
12+
public static void ClearLog(string dataPath)
1313
{
14-
string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
15-
Directory.CreateDirectory(_path);
14+
//string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
15+
Directory.CreateDirectory(dataPath);
1616
string _FileName = "Debug.txt";
17-
if (File.Exists(Path.Combine(_path, _FileName)))
17+
if (File.Exists(Path.Combine(dataPath, _FileName)))
1818
{
19-
File.Delete(Path.Combine(_path, _FileName));
19+
File.Delete(Path.Combine(dataPath, _FileName));
2020
}
2121
_text = "";
2222
}
@@ -27,31 +27,31 @@ public static void AddText(string Text)
2727
_text += dt + " " + Text + "\n";
2828
}
2929

30-
public static void LogText()
30+
public static void LogText(string dataPath)
3131
{
32-
string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
32+
//string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
3333
string dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
34-
Directory.CreateDirectory(_path);
34+
Directory.CreateDirectory(dataPath);
3535
string _FileName = "Debug.txt";
3636
if (Debug)
3737
{
38-
using (var writer = new StreamWriter(_path + "\\" + _FileName, true))
38+
using (var writer = new StreamWriter(dataPath + "\\" + _FileName, true))
3939
{
4040
writer.WriteLine(dt + " " + _text);
4141
}
4242
}
4343
_text = "";
4444
}
4545

46-
public static void LogNow(string Text)
46+
public static void LogNow(string dataPath, string Text)
4747
{
4848
string dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
49-
string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
50-
Directory.CreateDirectory(_path);
49+
//string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
50+
Directory.CreateDirectory(dataPath);
5151
string _FileName = "Debug.txt";
5252
if (Debug)
5353
{
54-
using (var writer = new StreamWriter(_path + "\\" + _FileName, true))
54+
using (var writer = new StreamWriter(dataPath + "\\" + _FileName, true))
5555
{
5656
writer.WriteLine(dt + " " + Text);
5757
}
@@ -67,7 +67,7 @@ public static void LogToEvent(Exception ex, EventLogEntryType Type, string text)
6767
EventLog.WriteEntry("WinSize4", text, Type, 1);
6868
}
6969
catch
70-
(Exception ex2)
70+
(Exception)
7171
{
7272
EventLog.WriteEntry("Application", text, Type, 1);
7373
}

ClsSavedWindows.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public class ClsSavedWindows
1515
{
1616
public List<ClsWindowProps> Props = new List<ClsWindowProps>();
17-
private string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
17+
//private string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
1818
private int _nextTag = 0;
1919

2020
//**********************************************
@@ -286,7 +286,7 @@ public int GetWindowIndexByTag(int Tag)
286286
//**********************************************
287287
/// <summary> Saves data to disk </summary>
288288
//**********************************************
289-
public void Save()
289+
public void Save(string dataPath)
290290
{
291291
string fileNameWindows;
292292
var options = new JsonSerializerOptions()
@@ -298,7 +298,7 @@ public void Save()
298298
int j;
299299

300300
// Remove all saved files
301-
var fileEntries = Directory.GetFiles(_path, "*.json");
301+
var fileEntries = Directory.GetFiles(dataPath, "*.json");
302302
foreach (string fileName in fileEntries)
303303
{
304304
if (Regex.Match(fileName, @"\d{3,5}x\d{3,5}P?\.json").Success)
@@ -327,12 +327,12 @@ public void Save()
327327
saveProps[saveProps.Count - 1].Add(this.Props[i]);
328328
}
329329
}
330-
Directory.CreateDirectory(_path);
330+
Directory.CreateDirectory(dataPath);
331331
for (int i = 0; i < saveProps.Count; i++)
332332
{
333333
fileNameWindows = saveProps[i][0].MonitorBoundsWidth + "x" + saveProps[i][0].MonitorBoundsHeight;
334334
fileNameWindows += (saveProps[i][0].Primary) ? "P.json" : ".json";
335-
using (var writer = new StreamWriter(_path + "\\" + fileNameWindows))
335+
using (var writer = new StreamWriter(dataPath + "\\" + fileNameWindows))
336336
{
337337
String json = JsonSerializer.Serialize(saveProps[i], options);
338338
writer.Write(json);
@@ -343,13 +343,13 @@ public void Save()
343343
//**********************************************
344344
/// <summary> Loads data from disk </summary>
345345
//**********************************************
346-
public void Load()
346+
public void Load(string dataPath)
347347
{
348348
this.Props.Clear();
349349
int Id = 0;
350-
System.IO.Directory.CreateDirectory(_path);
350+
System.IO.Directory.CreateDirectory(dataPath);
351351
List<ClsWindowProps> loadProps = new List<ClsWindowProps>();
352-
var fileEntries = Directory.GetFiles(_path, "*.json");
352+
var fileEntries = Directory.GetFiles(dataPath, "*.json");
353353
foreach (string fileName in fileEntries)
354354
{
355355
if (Regex.Match(fileName, @"\d{3,5}x\d{3,5}P?\.json").Success)

ClsScreens.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace WinSize4
99
public class ClsScreens
1010
{
1111
public List<ClsScreenList> ScreenList = new List<ClsScreenList>();
12-
private string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
12+
//private string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
1313
private string _fileNameWindows = "Screens.json";
1414

1515
//**********************************************
1616
/// <summary> Get all current screens </summary>
1717
/// <returns>True if a screen is added</returns>
1818
//**********************************************
19-
public bool AddNewScreens()
19+
public bool AddNewScreens(string dataPath)
2020
{
2121
bool Added = false;
2222
foreach (Screen screen in Screen.AllScreens)
@@ -48,7 +48,7 @@ public bool AddNewScreens()
4848
Y = screen.Bounds.Y,
4949
Primary = screen.Primary
5050
};
51-
ClsDebug.LogNow("AddNewScreens: New screen added " + screen.Bounds.Width + " " + screen.Bounds.Height + " " + screen.Primary);
51+
ClsDebug.LogNow(dataPath, "AddNewScreens: New screen added " + screen.Bounds.Width + " " + screen.Bounds.Height + " " + screen.Primary);
5252
this.ScreenList.Add(_newScreen);
5353
Added = true;
5454
}
@@ -80,7 +80,7 @@ public int GetScreenIndexForWindow(ClsWindowProps Props)
8080
/// <summary>Marks screens as present</summary>
8181
/// <returns>True if screen presence has changed</returns>
8282
//**********************************************
83-
public bool SetPresent()
83+
public bool SetPresent(string dataPath)
8484
{
8585
bool Changed = false;
8686
Screen[] AllScreens = System.Windows.Forms.Screen.AllScreens;
@@ -104,7 +104,7 @@ public bool SetPresent()
104104
if (this.ScreenList[i].Present == false)
105105
{
106106
Changed = true;
107-
ClsDebug.LogNow("SetPresent: Screen " + i + " is now present");
107+
ClsDebug.LogNow(dataPath, "SetPresent: Screen " + i + " is now present");
108108
}
109109
this.ScreenList[i].Present = true;
110110
}
@@ -113,7 +113,7 @@ public bool SetPresent()
113113
if (this.ScreenList[i].Present == true)
114114
{
115115
Changed = true;
116-
ClsDebug.LogNow("SetPresent: Screen " + i + " is no longer present");
116+
ClsDebug.LogNow(dataPath, "SetPresent: Screen " + i + " is no longer present");
117117
}
118118
this.ScreenList[i].Present = false;
119119
}
@@ -125,9 +125,9 @@ public bool SetPresent()
125125
/// <summary>Cleans out Screen no longer available</summary>
126126
/// <returns>True if at least one Screen was deleted</returns>
127127
//**********************************************
128-
public bool CleanScreenList()
128+
public bool CleanScreenList(string dataPath)
129129
{
130-
AddNewScreens();
130+
AddNewScreens(dataPath);
131131
bool Deleted = false;
132132
Screen[] CurrentScreens = Screen.AllScreens;
133133
//foreach (ClsScreenList ListScr in this.ScreenList)
@@ -145,7 +145,7 @@ public bool CleanScreenList()
145145
}
146146
if (!Found)
147147
{
148-
ClsDebug.LogNow("CleanScreenList: Screen deleted " + this.ScreenList[i].BoundsWidth + " " + this.ScreenList[i].BoundsHeight + "" + this.ScreenList[i].Primary);
148+
ClsDebug.LogNow(dataPath, "CleanScreenList: Screen deleted " + this.ScreenList[i].BoundsWidth + " " + this.ScreenList[i].BoundsHeight + "" + this.ScreenList[i].Primary);
149149
this.ScreenList.RemoveAt(i);
150150
Deleted = true;
151151
}
@@ -156,14 +156,14 @@ public bool CleanScreenList()
156156
//**********************************************
157157
/// <summary> Saves data to disk </summary>
158158
//**********************************************
159-
public void Save()
159+
public void Save(string dataPath)
160160
{
161161
var options = new JsonSerializerOptions()
162162
{
163163
WriteIndented = true
164164
};
165-
Directory.CreateDirectory(_path);
166-
using (var writer = new StreamWriter(_path + "\\" + _fileNameWindows))
165+
Directory.CreateDirectory(dataPath);
166+
using (var writer = new StreamWriter(dataPath + "\\" + _fileNameWindows))
167167
{
168168
String _json = JsonSerializer.Serialize(this.ScreenList, options);
169169
writer.Write(_json);
@@ -173,11 +173,11 @@ public void Save()
173173
//**********************************************
174174
/// <summary> Loads data from disk </summary>
175175
//**********************************************
176-
public void Load()
176+
public void Load(string dataPath)
177177
{
178-
if (File.Exists(_path + "\\" + _fileNameWindows))
178+
if (File.Exists(dataPath + "\\" + _fileNameWindows))
179179
{
180-
using (StreamReader r = new StreamReader(_path + "\\" + _fileNameWindows))
180+
using (StreamReader r = new StreamReader(dataPath + "\\" + _fileNameWindows))
181181
{
182182
String json = r.ReadToEnd();
183183
this.ScreenList = JsonSerializer.Deserialize<List<ClsScreenList>>(json);

ClsSettings.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
2+
using System.Diagnostics;
23
using System.IO;
4+
using System.Reflection;
35
using System.Text.Json;
46
using System.Windows.Forms;
7+
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
58

69
namespace WinSize4
710
{
@@ -14,12 +17,24 @@ public class ClsSettings
1417
public bool showAllWindows = true;
1518
public bool resetIfNewScreen = false;
1619
public bool runAtLogin = false;
17-
private string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
20+
public string dataPath = "";
1821
private string _fileNameWindows = "Settings.json";
1922
public bool Debug = false;
2023
public int Interval = 500;
2124
public bool isPaused = false;
2225

26+
public ClsSettings()
27+
{
28+
dataPath = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
29+
if (Directory.Exists(Directory.GetCurrentDirectory() + "\\data"))
30+
{
31+
dataPath = Directory.GetCurrentDirectory() + "\\data";
32+
}
33+
//ClsDebug.ClearLog(dataPath);
34+
//ClsDebug.LogNow(dataPath, "\nData directory is set to: " + dataPath);
35+
ClsDebug.LogToEvent(new Exception(), EventLogEntryType.Information, "\nData directory is set to: " + dataPath);
36+
}
37+
2338
//**********************************************
2439
/// <summary> Saves data to disk </summary>
2540
//**********************************************
@@ -40,8 +55,8 @@ public void SaveToFile()
4055
{
4156
WriteIndented = true
4257
};
43-
Directory.CreateDirectory(_path);
44-
using (var writer = new StreamWriter(_path + "\\" + _fileNameWindows))
58+
Directory.CreateDirectory(dataPath);
59+
using (var writer = new StreamWriter(dataPath + "\\" + _fileNameWindows))
4560
{
4661
String _json = JsonSerializer.Serialize(saveList, options);
4762
writer.Write(_json);
@@ -57,9 +72,9 @@ public void LoadFromFile()
5772
{
5873
ClsSettingsList saveList = new ClsSettingsList();
5974

60-
if (File.Exists(_path + "\\" + _fileNameWindows))
75+
if (File.Exists(dataPath + "\\" + _fileNameWindows))
6176
{
62-
using (StreamReader r = new StreamReader(_path + "\\" + _fileNameWindows))
77+
using (StreamReader r = new StreamReader(dataPath + "\\" + _fileNameWindows))
6378
{
6479
String json = r.ReadToEnd();
6580
saveList = JsonSerializer.Deserialize<ClsSettingsList>(json);
@@ -134,4 +149,4 @@ public int Interval
134149
public bool isPaused
135150
{ set; get; }
136151
}
137-
}
152+
}

ClsWindows.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public bool AlwaysMove
6464
{ set; get; } = false;
6565
public bool CanResize
6666
{ set; get; } = true;
67+
public bool Disabled
68+
{ get; set; } = false;
6769

6870
public const int Full = 0;
6971
public const int Contains = 1;

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,12 @@ This is what Windows considers the usable area, excluding the task bar area.
9696

9797
## Custom working area
9898
You can set your own working area, for example exclude an area to the right for gadgets that you don't want covered by windows.
99+
100+
# Portable mode
101+
It is possible to run WinSize4 without installing it. Download the ZIP file and extract it in any folder, run the file WinSize4.exe.
102+
103+
Data is by default saved in you personal application data folder (%localappdata%). If you don't want that, create a folder 'data' in the same folder as the exe file. When WinSize4 starts and detects this folder, it will save its data there.
104+
105+
Note that if you had data in your local application data folder will that data not be copied over, it will however remain.
106+
107+
WinSize4 creates entries in the event log under the Event Source 'WinSize4'. However, if you have not installed WinSize4 will those entries be saved under the generic Event Source 'Application'.

WinSize4.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
<UseWindowsForms>true</UseWindowsForms>
88
<ImplicitUsings>enable</ImplicitUsings>
99
<ApplicationIcon>001-direction.ico</ApplicationIcon>
10-
<AssemblyVersion>1.1.4.0</AssemblyVersion>
11-
<FileVersion>1.1.4.0</FileVersion>
10+
<AssemblyVersion>1.2.0.0</AssemblyVersion>
11+
<FileVersion>1.2.0.0</FileVersion>
12+
<Platforms>AnyCPU;X64;x86</Platforms>
1213
</PropertyGroup>
1314

1415
<ItemGroup>
@@ -34,4 +35,8 @@
3435
</None>
3536
</ItemGroup>
3637

38+
<ItemGroup>
39+
<Folder Include="Resources\" />
40+
</ItemGroup>
41+
3742
</Project>

0 commit comments

Comments
 (0)