Skip to content

Commit

Permalink
release version 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zmcj21 committed Feb 12, 2022
1 parent e93738d commit 605cd3c
Show file tree
Hide file tree
Showing 9 changed files with 2,683 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ OpenSource swf to exe converter.

### Usage

Download release version and open it.
Download newest release version and open it.

### References

Expand Down
2 changes: 1 addition & 1 deletion src/OpenSWF2EXE/OpenSWF2EXE/AboutForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions src/OpenSWF2EXE/OpenSWF2EXE/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
namespace OpenSWF2EXE
{
public static class Config
{
private static string configPath;

static Config()
{
configPath = Path.Combine(new string[] { Environment.CurrentDirectory, "s2e_config.txt" });
if (!File.Exists(configPath))
{
FileStream fileStream = File.Create(configPath);
fileStream.Close();
}
}

public static int GetLanguage()
{
string value = GetString("language", "2");
return int.Parse(value);
}

public static void SetLanguage(int value)
{
SetString("language", value.ToString());
}

public static string GetString(string key, string defaultVal)
{
string[] lines = File.ReadAllLines(configPath);

foreach (string line in lines)
{
int signIndex = line.IndexOf('=');
if (signIndex == -1) continue;

string keyStr = line.Substring(0, signIndex);
string keyStrWithoutSpace = keyStr.Trim();

//return first key
if (keyStrWithoutSpace.Equals(key))
{
string valueStr = line.Substring(signIndex + 1, line.Length - 1 - keyStr.Length);
string valueStrWithoutSpace = valueStr.Trim();
return valueStrWithoutSpace;
}
}

return defaultVal;
}

public static void SetString(string key, string value)
{
string[] lines = File.ReadAllLines(configPath);

//If the file is empty, just write!
if (lines.Length == 0 || (lines.Length == 1 && string.IsNullOrWhiteSpace(lines[0])))
{
string content = key + " = " + value;
File.WriteAllText(configPath, content);
return;
}

bool keyExists = false;
bool needToWrite = false;

for (int i = 0; i < lines.Length; i++)
{
string line = lines[i];

int signIndex = line.IndexOf('=');
if (signIndex == -1) continue;

string keyStr = line.Substring(0, signIndex);
string keyStrWithoutSpace = keyStr.Trim();
//Find first key
if (keyStrWithoutSpace.Equals(key))
{
keyExists = true;
string valueStr = line.Substring(signIndex + 1, line.Length - 1 - keyStr.Length);
string valueStrWithoutSpace = valueStr.Trim();
//If value changed
if (valueStrWithoutSpace != value)
{
needToWrite = true;
lines[i] = keyStrWithoutSpace + " = " + value;
}
break;
}
}

if (needToWrite)
{
File.WriteAllLines(configPath, lines);
}
else if (!keyExists)
{
string newLine = "\n" + key + " = " + value;
List<string> newLines = new List<string>();
newLines.AddRange(lines);
newLines.Add(newLine);
File.WriteAllLines(configPath, newLines.ToArray());
}
}
}
}
233 changes: 233 additions & 0 deletions src/OpenSWF2EXE/OpenSWF2EXE/EXE2SWF.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 605cd3c

Please sign in to comment.