Skip to content

Commit ba5957c

Browse files
committed
V2 initial pass. BROKEN MOSTLY
First pass at V2. New file format etc. All a horrible WIP.
1 parent cef47ad commit ba5957c

23 files changed

+1149
-611
lines changed

Format/BaseIOConfig.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
// The MIT License (MIT)
3+
//
4+
// Copyright (c) 2019 Tim Stair
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
////////////////////////////////////////////////////////////////////////////////
24+
25+
using System.IO;
26+
using KeyCap.Util;
27+
28+
namespace KeyCap.Format
29+
{
30+
public abstract class BaseIOConfig
31+
{
32+
public int Flags { get; set; }
33+
// https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
34+
public byte VirtualKey { get; set; }
35+
public int Parameter { get; set; }
36+
37+
public BaseIOConfig() { }
38+
39+
/// <summary>
40+
/// Constructor for an InputConfig
41+
/// </summary>
42+
/// <param name="byFlags">The flags defining the input</param>
43+
/// <param name="byVirtualKey">The value of the input</param>
44+
/// <param name="eKeyArgs">The input key arguments from user input</param>
45+
public BaseIOConfig(int nFlags, byte byVirtualKey, int nParameter)
46+
{
47+
Flags = nFlags;
48+
VirtualKey = byVirtualKey;
49+
Parameter = nParameter;
50+
}
51+
52+
public BaseIOConfig(Stream zStream)
53+
{
54+
Flags = StreamUtil.ReadIntFromStream(zStream);
55+
VirtualKey = StreamUtil.ReadByteFromStream(zStream);
56+
StreamUtil.ReadByteFromStream(zStream);
57+
StreamUtil.ReadByteFromStream(zStream);
58+
StreamUtil.ReadByteFromStream(zStream);
59+
Parameter = StreamUtil.ReadIntFromStream(zStream);
60+
}
61+
62+
/// <summary>
63+
/// Determines if the input type is flagged (as the there are multiple flags)
64+
/// </summary>
65+
/// <param name="eFlag">Flag to check for</param>
66+
/// <returns>true if the flag bit is 1, false otherwise</returns>
67+
public bool IsFlaggedAs(System.Enum eFlag)
68+
{
69+
return BitUtil.IsFlagged(Flags, eFlag);
70+
}
71+
72+
public abstract string GetDescription();
73+
74+
public void SerializeToStream(Stream zStream)
75+
{
76+
StreamUtil.WriteIntToStream(zStream, Flags);
77+
zStream.WriteByte(VirtualKey);
78+
zStream.WriteByte(0);
79+
zStream.WriteByte(0);
80+
zStream.WriteByte(0);
81+
StreamUtil.WriteIntToStream(zStream, Parameter);
82+
}
83+
}
84+
}

Format/ConfigFileManager.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
// The MIT License (MIT)
3+
//
4+
// Copyright (c) 2019 Tim Stair
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
////////////////////////////////////////////////////////////////////////////////
24+
25+
using System;
26+
using System.Collections.Generic;
27+
using System.IO;
28+
using System.Windows.Forms;
29+
using Support.UI;
30+
31+
namespace KeyCap.Format
32+
{
33+
public class ConfigFileManager
34+
{
35+
private static readonly int FILE_DATA_PREFIX = (int)0x0E0CA000;
36+
private static readonly int DATA_FORMAT_VERSION = (int)0x1;
37+
38+
public void SaveFile(List<RemapEntry> listRemapEntries, string sFileName)
39+
{
40+
var zFileStream = new FileStream(sFileName, FileMode.Create, FileAccess.Write, FileShare.None);
41+
StreamUtil.WriteIntToStream(zFileStream, FILE_DATA_PREFIX);
42+
StreamUtil.WriteIntToStream(zFileStream, DATA_FORMAT_VERSION);
43+
listRemapEntries.ForEach(zEntry =>
44+
{
45+
var arrayBytes = zEntry.SerializeToBytes();
46+
zFileStream.Write(arrayBytes, 0, arrayBytes.Length);
47+
});
48+
zFileStream.Close();
49+
}
50+
51+
public List<RemapEntry> LoadFile(string sFileName)
52+
{
53+
FileStream zFileStream = null;
54+
var listConfigs = new List<RemapEntry>();
55+
try
56+
{
57+
zFileStream = new FileStream(sFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
58+
var nPrefix = StreamUtil.ReadIntFromStream(zFileStream);
59+
if (nPrefix != FILE_DATA_PREFIX)
60+
{
61+
throw new Exception("{} does not have the correct data prefix. This is likely an unsupported format.".FormatString(sFileName));
62+
}
63+
64+
var nDataFormatVersion = StreamUtil.ReadIntFromStream(zFileStream);
65+
if (nDataFormatVersion != DATA_FORMAT_VERSION)
66+
{
67+
throw new Exception("{} indicates an unsupported data format.".FormatString(sFileName));
68+
}
69+
70+
while (zFileStream.Position < zFileStream.Length)
71+
{
72+
listConfigs.Add(new RemapEntry(zFileStream));
73+
}
74+
}
75+
catch (Exception e)
76+
{
77+
MessageBox.Show(e.Message);
78+
}
79+
finally
80+
{
81+
zFileStream?.Close();
82+
}
83+
84+
return listConfigs;
85+
}
86+
}
87+
}

Format/IODefinition.cs

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

0 commit comments

Comments
 (0)