如何将一些 C# 代码转换为 Pascal?
我有几个函数需要转换为 Pascal 以包含在我的 inno setup 安装程序中,以验证安装时的序列号。
任何帮助将不胜感激,因为我已经大约 8 年没有写过任何 pascal 了。
这是 C# 代码。
public static long DecodeAuthID(String keyset, String toDecode)
{
StringBuilder retval = new StringBuilder();
for (int i = 0; i < toDecode.Length; i++)
{
char[] toDecodeCharArray = toDecode.ToCharArray();
retval.Append(keyset.IndexOf(toDecodeCharArray[i]));
}
return Int32.Parse(retval.ToString());
}
public static string ReverseString(string stringToReverse)
{
char[] values = stringToReverse.ToCharArray();
Array.Reverse(values);
return new string(values);
}
private static void GetLocationFromAuthenticationID()
{
// Get Authentication Key from the Registry
string registryValue = GetAuthIDFromRegistry();
// Decode the Authentication Key to get the location
string value1 = ReverseString(registryValue);
string value2 = value1.Substring(0, 12);
string keyset = ReverseString(value2);
string valuesReversed = value1.Substring(12, value1.Length - 12);
string values = ReverseString(valuesReversed);
// Decode the AuthID
string authID = DecodeAuthID(keyset, values).ToString();
// Convert to Location ID
int locationID = Int32.Parse(authID) - (Int32.Parse(authID) - 1);
}
I have a couple of functions that I need to convert to Pascal to include in my inno setup installer, to validate a serial number on install.
Any assistance would be appreciated, as I haven't written any pascal in about 8 years.
Here is the C# code.
public static long DecodeAuthID(String keyset, String toDecode)
{
StringBuilder retval = new StringBuilder();
for (int i = 0; i < toDecode.Length; i++)
{
char[] toDecodeCharArray = toDecode.ToCharArray();
retval.Append(keyset.IndexOf(toDecodeCharArray[i]));
}
return Int32.Parse(retval.ToString());
}
public static string ReverseString(string stringToReverse)
{
char[] values = stringToReverse.ToCharArray();
Array.Reverse(values);
return new string(values);
}
private static void GetLocationFromAuthenticationID()
{
// Get Authentication Key from the Registry
string registryValue = GetAuthIDFromRegistry();
// Decode the Authentication Key to get the location
string value1 = ReverseString(registryValue);
string value2 = value1.Substring(0, 12);
string keyset = ReverseString(value2);
string valuesReversed = value1.Substring(12, value1.Length - 12);
string values = ReverseString(valuesReversed);
// Decode the AuthID
string authID = DecodeAuthID(keyset, values).ToString();
// Convert to Location ID
int locationID = Int32.Parse(authID) - (Int32.Parse(authID) - 1);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以看一下这个(未经测试,除了如果我注释掉未实现的
GetAuthIDFromRegistry
行,它会编译 - 无法测试,因为我没有您的问题中要使用的任何示例输入/输出数据)。它可能不是 100% 正确,但它至少应该让您朝着正确的方向开始。此处不包含源代码的所有函数均在“Pascal 脚本:支持函数参考”中的 InnoSetup 帮助文件中列出为受支持。
You can take a look at this (untested, other than it compiles if I comment out the line with
GetAuthIDFromRegistry
which is unimplemented - couldn't test because I don't have any sample input/output data to work with from your question). It may not be 100% correct, but it should at least get you started in the right direction.All of the functions not containing source here are listed as supported in the InnoSetup help file in either the "Pascal Scripting: Support Functions Reference".
您可以尝试使用 C# 到 Oxygene 转换器 来将其转换为 Oxygene,Oxygene 用于德尔福棱镜。
问题是此代码使用了 InnoSetup 中不可用的 .NET 类(如 StringBuilder)和转换器(Int32.Parse)。
You can try the C# to Oxygene converter that does this conversion to Oxygene, the Object Pascal used in Delphi Prism.
The problem is that this code makes use of .NET classes (like StringBuilder) and converters (Int32.Parse) that are not available in InnoSetup.