-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Windows.Forms; | ||
using System.Linq; | ||
using System.IO; | ||
using System; | ||
|
||
namespace ElegantRecorder | ||
{ | ||
public static class Util | ||
{ | ||
public static string HotkeyToString(int hotkey) | ||
{ | ||
return string.Join("+", ((Keys)hotkey).ToString().Split(", ").Reverse()); | ||
} | ||
|
||
public static string ReadUntil(FileStream Stream, string UntilText) | ||
{ | ||
System.Text.StringBuilder builder = new System.Text.StringBuilder(); | ||
System.Text.StringBuilder returnTextBuilder = new System.Text.StringBuilder(); | ||
string returnText = string.Empty; | ||
int size = Convert.ToInt32(UntilText.Length / (double)2) - 1; | ||
byte[] buffer = new byte[size + 1]; | ||
int currentRead = -1; | ||
|
||
while (currentRead != 0) | ||
{ | ||
string collected = null; | ||
string chars = null; | ||
int foundIndex = -1; | ||
|
||
currentRead = Stream.Read(buffer, 0, buffer.Length); | ||
chars = System.Text.Encoding.Default.GetString(buffer, 0, currentRead); | ||
|
||
builder.Append(chars); | ||
returnTextBuilder.Append(chars); | ||
|
||
collected = builder.ToString(); | ||
foundIndex = collected.IndexOf(UntilText); | ||
|
||
if (foundIndex >= 0) | ||
{ | ||
returnText = returnTextBuilder.ToString(); | ||
|
||
int indexOfSep = returnText.IndexOf(UntilText); | ||
int cutLength = returnText.Length - indexOfSep; | ||
|
||
returnText = returnText.Remove(indexOfSep, cutLength); | ||
|
||
builder.Remove(0, foundIndex + UntilText.Length); | ||
|
||
if (cutLength > UntilText.Length) | ||
Stream.Position -= cutLength - UntilText.Length; | ||
|
||
return returnText; | ||
} | ||
else if (!collected.Contains(UntilText.First())) | ||
builder.Length = 0; | ||
} | ||
|
||
return string.Empty; | ||
} | ||
} | ||
} |