/// <summary> /// Expand up to path of given problem number and select top file inside that folder /// Prompt for new file if none exist /// </summary> /// <param name="pnum">Problem number</param> public void ShowCode(object pnum) { if (!Directory.Exists(RegistryAccess.CodesPath)) { return; } if (!IsReady || folderTreeView.Nodes.Count == 0) { if (this.IsDisposed) { return; } TaskQueue.AddTask(ShowCode, pnum, 1000); return; } //create code file if doesn't exist string path = LocalDirectory.GetCodesPath((long)pnum); if (!Directory.Exists(path) || Directory.GetFiles(path).Length == 0) { this.BeginInvoke((MethodInvoker)(() => AddProblem((long)pnum))); return; } this.BeginInvoke((MethodInvoker) delegate { //select code file path TreeNode tn = GetNode(new DirectoryInfo(path)); CodesBrowser.ExpandAndSelect(tn, CodesBrowser.ExpandSelectType.SelecFirstChild); }); }
public void AddProblem(long pnum) { //get code path string path = LocalDirectory.GetCodesPath(pnum); if (string.IsNullOrEmpty(path)) { return; } //get language CodeFileCreator cfc = new CodeFileCreator(); if (cfc.ShowDialog() != DialogResult.OK) { return; } Structures.Language lang = cfc.Language; cfc.Dispose(); //get file extension string ext = ".cpp"; if (lang == Structures.Language.C) { ext = ".c"; } else if (lang == Structures.Language.Java) { ext = ".java"; } else if (lang == Structures.Language.Pascal) { ext = ".pascal"; } //create code file string name = Path.GetFileName(path); CreateFile(path, name, ext); //create input-output string input = Path.Combine(path, "input.txt"); string output = Path.Combine(path, "output.txt"); string correct = Path.Combine(path, "correct.txt"); LocalDirectory.CreateFile(input); LocalDirectory.CreateFile(output); LocalDirectory.CreateFile(correct); ParseInputOutput(pnum, input, correct); //select created problem this.BeginInvoke((MethodInvoker) delegate { ExpandAndSelect(LocateProblem(pnum), ExpandSelectType.SelecFirstChild); }); }
/// <summary> /// Formats the code directory with default files and folders /// </summary> /// <param name="background">True to run this process on background</param> public void FormatCodeDirectory(object background) { if (!IsReady) { return; } //gather all files string path = RegistryAccess.CodesPath; if (!Directory.Exists(path)) { return; } if ((bool)background) { System.Threading.ThreadPool.QueueUserWorkItem(FormatCodeDirectory, false); return; } IsReady = false; Interactivity.SetStatus("Formatting code directory started..."); this.BeginInvoke((MethodInvoker) delegate { selectDirectoryPanel.Visible = false; folderTreeView.UseWaitCursor = true; }); //create codes-path and check them if (!LocalDatabase.IsReady) { Logger.Add("Problem Database is not ready.", "Codes | FormatCodeDirectory()"); return; } //just call codesPath. it will create directory automatically foreach (Structures.ProblemInfo prob in LocalDatabase.problemList) { LocalDirectory.GetCodesPath(prob.pnum); } //now create files for precode LocalDirectory.GetPrecode(Structures.Language.C); LocalDirectory.GetPrecode(Structures.Language.CPP); LocalDirectory.GetPrecode(Structures.Language.Java); LocalDirectory.GetPrecode(Structures.Language.Pascal); IsReady = true; LoadCodeFolder(false); Interactivity.SetStatus("Formatting code directory finished."); }
public TreeNode LocateProblem(long pnum) { string path = LocalDirectory.GetCodesPath(pnum); return(GetNode(new DirectoryInfo(path))); }
/// <summary> /// Import old uva codes into new folder /// </summary> public void ImportOldCodes(object state) { if (!IsReady) { return; } object[] data = (object[])state; bool background = (bool)data[0]; string oldpath = (string)data[1]; if (background) { data[0] = false; System.Threading.ThreadPool.QueueUserWorkItem(ImportOldCodes, data); return; } IsReady = false; try { Interactivity.SetStatus("Importing codes..."); //get current path string path = RegistryAccess.CodesPath; if (!Directory.Exists(path)) { return; } //copy all files foreach (string file in Directory.GetFiles(oldpath, "*.*", SearchOption.AllDirectories)) { //get problem number guesses List <int> guesses = new List <int>(); int tmp = 0; foreach (char ch in Path.GetFileNameWithoutExtension(file)) { if (char.IsNumber(ch)) { tmp = tmp * 10 + ch - '0'; } else { if (tmp > 0) { guesses.Add(tmp); } tmp = 0; } } //check if a guess matches Structures.ProblemInfo pinfo = null; foreach (int item in guesses) { pinfo = LocalDatabase.GetProblem(item); if (pinfo != null) { break; } } if (pinfo == null) { continue; } //copy this file to guessed problem directory string code = CreateFile( LocalDirectory.GetCodesPath(pinfo.pnum), Path.GetFileNameWithoutExtension(file), Path.GetExtension(file)); if (code == null) { continue; } File.Copy(file, code, true); Interactivity.SetStatus("Importing codes... [" + pinfo.pnum.ToString() + "]"); } } catch (Exception ex) { Logger.Add(ex.Message, "ImportCodes()|CodesBrowser"); } finally { Interactivity.SetStatus("Finished importing codes."); IsReady = true; } LoadCodeFolder(false); }