public void ST(string msg) { try { StatusLabel.Text = msg; StatusLabel.Update(); StatusLabel.Refresh(); } catch { } }
private void SearchFilesQueue() { if (PathTextBox.Text.Length > 0 && DateTextBox.Text.Length > 0) { StatusLabel.Text = "Zähle Dateien... Das kann sehr lange dauern..."; StatusLabel.Update(); //get the list of files. This can be run for a long! time.. IEnumerable <string> files = EnumerateFiles(PathTextBox.Text); DateTime fileCreationDate; DateTime searchDate = DateTime.Parse(DateTextBox.Text); int counter = 0; int lastTick = 0; int amount = files.Count <string>(); foreach (var file in files) { counter++; //Console.WriteLine(file); //fileCreationDate = File.GetCreationTime(file); FileSystemInfo fsi = new FileInfo(file); fileCreationDate = fsi.CreationTime; // System.IO.DirectoryInfo.EnumerateFiles(file) ;//.Crea; if (fileCreationDate < searchDate) { if (FilesListBox.Items.Count == lastTick) { //Console.WriteLine(lastTick+" Dateien gefunden..."); StatusLabel.Text = counter + " / " + amount + " Dateien durchsucht und " + lastTick + " alte Dateien gefunden"; StatusLabel.Update(); FilesListBox.Update(); lastTick += 100; } FilesListBox.Items.Add(file); } } StatusLabel.Text = FilesListBox.Items.Count + " Dateien gefunden"; StatusLabel.Update(); MessageBox.Show("Es gibt " + FilesListBox.Items.Count + " Dateien, die den Suchparametern entsprechen!"); StatusLabel1.Text = ""; StatusLabel1.Update(); } }
private void BGWorker_DoWork(object sender, DoWorkEventArgs e) { BgWorkerInformation BgData = (BgWorkerInformation)e.Argument; string[] VarLines = BgData.VarText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); int NumVars = 0; List <string> VarPlaceholders = new List <string>(); //get all of the split out info into a list List <Array> VarList = new List <Array>(); for (int i = 0; i < VarLines.Length; i++) { string[] VarList_Split = (VarLines[i].Trim().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)); if (VarList_Split.Length > 1) { NumVars++; VarList.Add(VarList_Split.ToList().GetRange(1, VarList_Split.Length - 1).ToArray()); VarPlaceholders.Add(VarList_Split[0]); } } try { StatusLabel.Invoke((MethodInvoker) delegate { StatusLabel.Text = "Recursing variable combinations... This might take a while..."; }); //Set up our code List <string> RecursedVars = Recursion(0, VarList).Distinct().ToList(); using (StreamWriter outputFile = new StreamWriter(new FileStream(BgData.FileOutputLocation, FileMode.Create, FileAccess.Write), Encoding.UTF8)) { outputFile.WriteLine("Input Variable Data:"); outputFile.WriteLine(BgData.VarText + "\r\n\r\n"); outputFile.WriteLine("Input Code Data:"); outputFile.WriteLine(BgData.CodeText + "\r\n\r\n"); outputFile.WriteLine("Code Output:\r\n"); int LineCount = RecursedVars.Count; LineCountString = LineCount.ToString(); for (int i = 0; i < LineCount; i++) { StringBuilder OutputCode = new StringBuilder(); OutputCode.Append(BgData.CodeText); StatusLabel.Invoke((MethodInvoker) delegate { StatusLabel.Text = "Writing line " + (i + 1).ToString() + " of " + LineCountString; StatusLabel.Invalidate(); StatusLabel.Update(); StatusLabel.Refresh(); Application.DoEvents(); }); string[] Var_Replacements = RecursedVars[i].Split(' '); for (int j = 0; j < NumVars; j++) { OutputCode.Replace(VarPlaceholders[j], Var_Replacements[j]); } outputFile.WriteLine(OutputCode.ToString()); } } e.Result = BgData.FileOutputLocation; } catch { MessageBox.Show("An error occurred while building your code.", "Ruh-roh!", MessageBoxButtons.OK, MessageBoxIcon.Error); e.Result = null; } }
private void BgWorkerClean_DoWork(object sender, DoWorkEventArgs e) { DictionaryData BGWorkerData = (DictionaryData)e.Argument; TranslationClient client = TranslationClient.Create(); //selects the text encoding based on user selection Encoding InputSelectedEncoding = null; Encoding OutputSelectedEncoding = null; this.Invoke((MethodInvoker) delegate() { InputSelectedEncoding = Encoding.GetEncoding(InputEncodingDropdown.SelectedItem.ToString()); OutputSelectedEncoding = Encoding.GetEncoding(OutputEncodingDropdown.SelectedItem.ToString()); }); //get the list of files var SearchDepth = SearchOption.TopDirectoryOnly; if (ScanSubfolderCheckbox.Checked) { SearchDepth = SearchOption.AllDirectories; } var files = Directory.EnumerateFiles(BGWorkerData.TextFileFolder, BGWorkerData.FileExtension, SearchDepth); try { foreach (string fileName in files) { if (e.Cancel) { break; } //set up our variables to report string Filename_Clean = Path.GetFileName(fileName); string SubDirStructure = Path.GetDirectoryName(fileName).Replace(BGWorkerData.TextFileFolder, "").TrimStart('\\'); //creates subdirs if they don't exist string Output_Location = BGWorkerData.OutputFileLocation + '\\' + SubDirStructure; if (!Directory.Exists(Output_Location)) { Directory.CreateDirectory(Output_Location); } Output_Location = Path.Combine(Output_Location, Path.GetFileName(fileName)); //report what we're working on FilenameLabel.Invoke((MethodInvoker) delegate { FilenameLabel.Text = "Processing: " + Filename_Clean; FilenameLabel.Invalidate(); FilenameLabel.Update(); FilenameLabel.Refresh(); Application.DoEvents(); }); // __ __ _ _ ___ _ _ // \ \ / / __(_) |_ ___ / _ \ _ _| |_ _ __ _ _| |_ // \ \ /\ / / '__| | __/ _ \ | | | | | | | __| '_ \| | | | __| // \ V V /| | | | || __/ | |_| | |_| | |_| |_) | |_| | |_ // \_/\_/ |_| |_|\__\___| \___/ \__,_|\__| .__/ \__,_|\__| // |_| using (StreamReader inputfile = new StreamReader(fileName, InputSelectedEncoding)) { if (e.Cancel) { break; } string readText = inputfile.ReadToEnd(); string[] readText_Chunked = new string[0]; if (!string.IsNullOrWhiteSpace(readText)) { readText_Chunked = SplitStringByLength(readText, BGWorkerData.MaxCharsPerRequest); } StringBuilder TranslatedText_Output = new StringBuilder(); for (int i = 0; i < readText_Chunked.Length; i++) { if (e.Cancel) { break; } try { if (e.Cancel) { break; } StatusLabel.Invoke((MethodInvoker) delegate { StatusLabel.Text = "Status: Sending request " + (i + 1).ToString() + "/" + readText_Chunked.Length.ToString() + " to API..."; StatusLabel.Invalidate(); StatusLabel.Update(); StatusLabel.Refresh(); Application.DoEvents(); }); var response = client.TranslateText(readText_Chunked[i], sourceLanguage: BGWorkerData.InputLang, targetLanguage: BGWorkerData.OutputLang); TranslatedText_Output.Append(response.TranslatedText + " "); } catch (Google.GoogleApiException ex) { if (e.Cancel) { break; } if (ex.Error.Code == 403) { if (ex.Error.Message.Contains("Daily Limit Exceeded")) { //report what we're working on StatusLabel.Invoke((MethodInvoker) delegate { StatusLabel.Text = "Status: " + ex.Error.Message; StatusLabel.Invalidate(); StatusLabel.Update(); StatusLabel.Refresh(); Application.DoEvents(); }); MessageBox.Show("The Google Translate API reports that you have exceeded your daily use limit. You will need to visit the \"Quotas\" section of the Google Cloud Dashboard to increase your limits or, alternatively, wait until midnight for your quota to reset.", "Daily Limit Exceeded", MessageBoxButtons.OK, MessageBoxIcon.Stop); e.Cancel = true; break; } else { if (e.Cancel) { break; } int retry_counter = 0; while (retry_counter < BGWorkerData.MaxRetries) { retry_counter++; int TimerCounter = 0; DateTime d = DateTime.Now; while (TimerCounter < BGWorkerData.DurationLength + 2) { TimeSpan ts = DateTime.Now.Subtract(d); if (ts.Seconds >= 1) { //do some work TimerCounter += ts.Seconds; d = DateTime.Now; //report what we're working on StatusLabel.Invoke((MethodInvoker) delegate { StatusLabel.Text = "Status: Rate limit reached. Sleeping for " + (BGWorkerData.DurationLength - TimerCounter + 1).ToString() + "..."; StatusLabel.Invalidate(); StatusLabel.Update(); StatusLabel.Refresh(); Application.DoEvents(); }); } } try { //report what we're working on StatusLabel.Invoke((MethodInvoker) delegate { StatusLabel.Text = "Status: Sending request " + (i + 1).ToString() + "/" + readText_Chunked.Length.ToString() + " to API... Retry #" + retry_counter.ToString(); StatusLabel.Invalidate(); StatusLabel.Update(); StatusLabel.Refresh(); Application.DoEvents(); }); var response = client.TranslateText(readText_Chunked[i], sourceLanguage: BGWorkerData.InputLang, targetLanguage: BGWorkerData.OutputLang); TranslatedText_Output.Append(response.TranslatedText + " "); retry_counter = BGWorkerData.MaxRetries; } catch { } } } } else if (ex.Error.Code == 429 || (ex.Error.Code >= 500 && ex.Error.Code < 600)) { int retry_counter = 0; while (retry_counter < BGWorkerData.MaxRetries) { retry_counter++; int TimerCounter = 0; DateTime d = DateTime.Now; while (TimerCounter < System.Math.Pow(retry_counter, 2)) { TimeSpan ts = DateTime.Now.Subtract(d); if (ts.Seconds >= 1) { //do some work TimerCounter += ts.Seconds; d = DateTime.Now; //report what we're working on StatusLabel.Invoke((MethodInvoker) delegate { StatusLabel.Text = "Status: Error " + ex.Error.Code.ToString() + "; " + ex.Error.Message + " -- Retrying in " + (BGWorkerData.DurationLength - TimerCounter + 1).ToString() + "..."; StatusLabel.Invalidate(); StatusLabel.Update(); StatusLabel.Refresh(); Application.DoEvents(); }); } } try { //report what we're working on StatusLabel.Invoke((MethodInvoker) delegate { StatusLabel.Text = "Status: Sending request " + (i + 1).ToString() + "/" + readText_Chunked.Length.ToString() + " to API... Retry #" + retry_counter.ToString(); StatusLabel.Invalidate(); StatusLabel.Update(); StatusLabel.Refresh(); Application.DoEvents(); }); var response = client.TranslateText(readText_Chunked[i], sourceLanguage: BGWorkerData.InputLang, targetLanguage: BGWorkerData.OutputLang); TranslatedText_Output.Append(response.TranslatedText + " "); retry_counter = BGWorkerData.MaxRetries; } catch { } } } else { //report what we're working on StatusLabel.Invoke((MethodInvoker) delegate { StatusLabel.Text = "Status: " + ex.Error.Message; StatusLabel.Invalidate(); StatusLabel.Update(); StatusLabel.Refresh(); Application.DoEvents(); }); } } } //open up the output file using (StreamWriter outputFile = new StreamWriter(new FileStream(Output_Location, FileMode.Create), OutputSelectedEncoding)) { outputFile.Write(TranslatedText_Output.ToString()); } } } } catch (Exception ex) { MessageBox.Show("Transmogrifier encountered an issue somewhere while trying to translate your texts. The most common cause of this is trying to open your output file(s) while the program is still running. Did any of your input files move, or is your output file being opened/modified by another application? " + "After clicking the \"OK\" Button, you will receive an error code. Please write down this error code (or take a screenshot) and contact the software's author ([email protected]) for additional help.", "Error while translating", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.ToString(), "Error Code", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void StartButton_Click(object sender, EventArgs e) { string sTemp; int iTemp; string[] LogFiles; // Dim AiFile As String int CountMark = -1; // Array.Clear(X, 0, X.Length) // Array.Clear(Y, 0, Y.Length) System.IO.StreamReader inFile; FolderBrowserDialog.SelectedPath = Environment.CurrentDirectory; if (FolderBrowserDialog.ShowDialog() == DialogResult.Cancel) { return; } LogFiles = System.IO.Directory.GetFiles(FolderBrowserDialog.SelectedPath, "*.log", System.IO.SearchOption.AllDirectories); if (LogFiles.Length < 1) { MessageBox.Show(@"No log files in folder. Try again and select correct folder with files from LodD\err server folder", "No log files", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (System.IO.File.Exists("ai.obj") == false) { MessageBox.Show("Need file AI.obj for scanning bad teleport positions", "Required AI.obj", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (System.IO.File.Exists("npcpos.txt") == false) { MessageBox.Show("Need file npcpos.txt for scanning bad teleport positions", "Required npcpos.txt", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (System.IO.File.Exists("setting.txt") == false) { MessageBox.Show("Need file setting.txt for scanning bad teleport positions", "Required setting.txt", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ProgressBar.Maximum = LogFiles.Length - 1; ProgressBar.Value = 0; var loopTo = LogFiles.Length - 1; for (iTemp = 0; iTemp <= loopTo; iTemp++) { inFile = new System.IO.StreamReader(LogFiles[iTemp], System.Text.Encoding.Default, true, 1); ProgressBar.Value = iTemp; StatusLabel.Text = "Scanning file... " + System.IO.Path.GetFileName(LogFiles[iTemp]); StatusLabel.Update(); while (inFile.EndOfStream != true) { sTemp = inFile.ReadLine(); if (Strings.InStr(sTemp, "container NULL pos[") != 0) { // Found error // 03/26/2007 00:02:55.977, container NULL pos[-12694, 122776] at file [.\world_server.cpp], line [740] sTemp = Strings.Mid(sTemp, Strings.InStr(sTemp, "pos[") + 4, Strings.InStr(sTemp, "]") - Strings.InStr(sTemp, "pos[") - 4).Replace(",", ";").Replace(" ", ""); if (Array.IndexOf(XY, sTemp) == -1) { CountMark += 1; XY[CountMark] = sTemp; } } } inFile.Close(); } ProgressBar.Value = 0; // SCANNING Ai.obj for bad telposlist // telposlist_begin Position // {"Dion Castle Town"; 15671; 142994; -2704; 8100; 2 } // telposlist_end var TelPos = new string[6]; StatusLabel.Text = "Scanning AI.obj for finding bad Z..."; StatusLabel.Update(); inFile = new System.IO.StreamReader("ai.obj", System.Text.Encoding.Default, true, 1); ProgressBar.Maximum = Conversions.ToInteger(inFile.BaseStream.Length); ProgressBar.Value = 0; while (inFile.EndOfStream != true) { sTemp = inFile.ReadLine(); if (Strings.InStr(sTemp, "telposlist_begin") != 0) { sTemp = inFile.ReadLine(); while (Strings.InStr(sTemp, "telposlist_end") == 0) { TelPos = sTemp.Replace(" ", "").Split(Conversions.ToChar(";")); iTemp = Array.IndexOf(XY, TelPos[1] + ";" + TelPos[2]); if (iTemp != -1) { // Found teleport in list XYAi[XYAi.Length - 1] = TelPos[1] + "; " + TelPos[2] + "; " + TelPos[3] + Constants.vbTab + sTemp.Trim(); Array.Resize(ref XYAi, XYAi.Length + 1); // XY(iTemp) = TelPos(1) & "; " & TelPos(2) & "; " & TelPos(3) // clear status XY[iTemp] = ""; } sTemp = inFile.ReadLine(); } ProgressBar.Value = Conversions.ToInteger(inFile.BaseStream.Position); } } inFile.Close(); ProgressBar.Value = 0; // ai_parameters={[SSQLoserTeleport]=@SEAL_REVELATION;[SSQTelPosX]=[39139];[SSQTelPosY]=[143888];[SSQTelPosZ]=[-3648]} StatusLabel.Text = "Scanning Npcpos.txt for finding bad Z..."; StatusLabel.Update(); inFile = new System.IO.StreamReader("Npcpos.txt", System.Text.Encoding.Default, true, 1); ProgressBar.Maximum = Conversions.ToInteger(inFile.BaseStream.Length); ProgressBar.Value = 0; while (inFile.EndOfStream != true) { sTemp = inFile.ReadLine(); var loopTo1 = CountMark // XY.Length ; for (iTemp = 0; iTemp <= loopTo1; iTemp++) { if (!string.IsNullOrEmpty(XY[iTemp])) { TelPos = XY[iTemp].Replace(" ", "").Split(Conversions.ToChar(";")); if (Strings.InStr(sTemp, "[" + TelPos[0] + "]") != 0 & Strings.InStr(sTemp, "[" + TelPos[1] + "]") != 0) { XYNpcpos[XYNpcpos.Length - 1] = TelPos[0] + "; " + TelPos[1] + Constants.vbTab + Libraries.GetNeedParamFromStr(sTemp, "ai_parameters"); Array.Resize(ref XYNpcpos, XYNpcpos.Length + 1); XY[iTemp] = ""; break; } } } ProgressBar.Value = Conversions.ToInteger(inFile.BaseStream.Position); } inFile.Close(); ProgressBar.Value = 0; // point1 = {-103125;-209047;-3357} StatusLabel.Text = "Scanning setting.txt for finding bad Z..."; StatusLabel.Update(); inFile = new System.IO.StreamReader("setting.txt", System.Text.Encoding.Default, true, 1); ProgressBar.Maximum = Conversions.ToInteger(inFile.BaseStream.Length); ProgressBar.Value = 0; while (inFile.EndOfStream != true) { sTemp = inFile.ReadLine(); var loopTo2 = CountMark // XY.Length ; for (iTemp = 0; iTemp <= loopTo2; iTemp++) { if (!string.IsNullOrEmpty(XY[iTemp])) { if (Strings.InStr(sTemp.Replace(" ", ""), XY[iTemp]) != 0) { // TelPos = XY(iTemp).Replace(" ", "").Split(CChar(";")) XYSetting[XYSetting.Length - 1] = XY[iTemp] + Constants.vbTab + sTemp.Trim(); // XYNpcpos(XYNpcpos.Length - 1) = Libraries.GetNeedParamFromStr(sTemp, "ai_parameters") Array.Resize(ref XYSetting, XYSetting.Length + 1); XY[iTemp] = ""; break; } } } ProgressBar.Value = Conversions.ToInteger(inFile.BaseStream.Position); } inFile.Close(); ProgressBar.Value = 0; // Save results StatusLabel.Text = "Save bad teleport positions to file... ~contanterNULLpos.log"; StatusLabel.Update(); var outFile = new System.IO.StreamWriter("~contanterNULLpos.log", false, System.Text.Encoding.Unicode, 1); outFile.WriteLine("L2ScriptMaker: Error 'container NULL pos[' scanner..." + Constants.vbNewLine + Conversions.ToString(DateAndTime.Now) + Constants.vbTab + "Start"); outFile.WriteLine(Constants.vbNewLine + "AI.obj scanning log:"); var loopTo3 = XYAi.Length - 1; for (iTemp = 0; iTemp <= loopTo3; iTemp++) { outFile.WriteLine(XYAi[iTemp]); } outFile.WriteLine(Constants.vbNewLine + "Npcpos scanning log:"); var loopTo4 = XYNpcpos.Length - 1; for (iTemp = 0; iTemp <= loopTo4; iTemp++) { outFile.WriteLine(XYNpcpos[iTemp]); } outFile.WriteLine(Constants.vbNewLine + "Setting scanning log:"); var loopTo5 = XYSetting.Length - 1; for (iTemp = 0; iTemp <= loopTo5; iTemp++) { outFile.WriteLine(XYSetting[iTemp]); } outFile.WriteLine(Constants.vbNewLine + "Undefined positions scanning log:"); var loopTo6 = XY.Length - 1; for (iTemp = 0; iTemp <= loopTo6; iTemp++) { if (!string.IsNullOrEmpty(XY[iTemp])) { outFile.WriteLine(XY[iTemp]); } } outFile.WriteLine(Constants.vbNewLine + Conversions.ToString(DateAndTime.Now) + Constants.vbTab + "End"); outFile.Close(); StatusLabel.Text = "Step1 complete."; StatusLabel.Update(); MessageBox.Show("Step1 complete. Open file ~contanterNULLpos.log, teleport to this positions, get correct Z and edit file", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void ApplyPatchButton_Click(object sender, EventArgs e) { if (System.IO.File.Exists("ai.obj") == false) { MessageBox.Show("Need file AI.obj for fixing bad teleport positions", "Required AI.obj", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string sTemp; int iTemp; int CountMark = -1; var TelPos = new string[6]; OpenFileDialog.Title = "Select file what have correct coordinates. Plain file with X;Y;Z"; OpenFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; if (OpenFileDialog.ShowDialog() == DialogResult.Cancel) { return; } Array.Clear(XY, 0, XY.Length); var inFile = new System.IO.StreamReader(OpenFileDialog.FileName, System.Text.Encoding.Default, true, 1); while (inFile.EndOfStream != true) { sTemp = inFile.ReadLine(); if (!string.IsNullOrEmpty(sTemp)) { TelPos = sTemp.Replace(" ", "").Split(Conversions.ToChar(";")); CountMark += 1; // XY(CountMark) = Join(TelPos, ";") XY[CountMark] = TelPos[0] + ";" + TelPos[1]; Z[CountMark] = TelPos[2]; } } inFile.Close(); System.IO.File.Copy("ai.obj", "ai.obj.bak", true); inFile = new System.IO.StreamReader("ai.obj.bak", System.Text.Encoding.Default, true, 1); var outFile = new System.IO.StreamWriter("ai.obj", false, System.Text.Encoding.Unicode, 1); ProgressBar.Maximum = Conversions.ToInteger(inFile.BaseStream.Length); ProgressBar.Value = 0; while (inFile.EndOfStream != true) { sTemp = inFile.ReadLine(); outFile.WriteLine(sTemp); if (Strings.InStr(sTemp, "telposlist_begin") != 0) { sTemp = inFile.ReadLine(); while (Strings.InStr(sTemp, "telposlist_end") == 0) { TelPos = sTemp.Replace(" ", "").Split(Conversions.ToChar(";")); iTemp = Array.IndexOf(XY, TelPos[1] + ";" + TelPos[2]); if (iTemp != -1) { // Found teleport in list // {"Dion Castle Town"; 15671; 142994; -2704; 8100; 2 } // TelPos(3) = Z(iTemp) // sTemp = TelPos(0) & "; " & XY(iTemp).Replace(";", "; ") & "; " & Z(iTemp) & "; " & TelPos(4) & "; " & TelPos(5) // sTemp = Join(TelPos, " ;") sTemp = sTemp.Replace(TelPos[3], Z[iTemp]); } outFile.WriteLine(sTemp); sTemp = inFile.ReadLine(); } outFile.WriteLine(sTemp); ProgressBar.Value = Conversions.ToInteger(inFile.BaseStream.Position); } } outFile.Close(); ProgressBar.Value = 0; StatusLabel.Text = "Step2 complete."; StatusLabel.Update(); MessageBox.Show("Step2 complete. Fixed file is AI.obj", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); }