public bool CreateVMTFiles() { _textLog.Text = null; bool bCreated = false; for (int i = 0; i < _files.Count(); i++) { string path = string.Format("{0}\\{1}{2}", Path.GetDirectoryName(_files[i]), _prefix, Path.GetFileName(_files[i])); string texturePath = string.Format("{0}{1}", _texturePath, Path.GetFileNameWithoutExtension(path)); texturePath = texturePath.ToLower().Replace("\\", "/"); string script = _script.Replace("%path%", texturePath); _textLog.Text += string.Format("Created .vmt for {0}!", Path.GetFileNameWithoutExtension(path)) + Environment.NewLine; try { Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllText(path, script); } catch { LoggingUtils.LogEvent("Unable to create .vmt file!"); } bCreated = true; } return(bCreated); }
private void RemoveFile(TreeNode node, bool bDelete = false) { if (node == null) { return; } TreeNode parent = node.Parent; if (parent == null || (node.Nodes.Count > 0)) { return; } string path = ProjectUtils.GetFilePathForTreeNodeItem(node.Parent.Text, node.Text); if (ProjectUtils.RemoveFile(node.Text, node.Parent.Text)) { WindowHandler.DeregisterWindow(node.Text, node.Parent.Text); parent.Nodes.Remove(node); if (bDelete && File.Exists(path)) { try { File.Delete(path); } catch { LoggingUtils.LogEvent(string.Format("Unable to delete file {0}!", path)); } } } }
public static string GetUrlStream(string url) { try { return(new WebClient().DownloadString(url)); } catch { LoggingUtils.LogEvent("Unable to read url for KeyValues!"); return(null); } }
private void ParseData() { // Find the next key to parse: int iStart = GetFirstBracket(); while (iStart != -1) { List <string> newData = new List <string>(); int iEnd = GetLastBracket(iStart + 2); for (int i = iStart; i < iEnd; i++) { newData.Add(_internalData[i]); } // Remove stuff we no longer need. for (int i = (iEnd - 1); i >= iStart; i--) { _internalData.RemoveAt(i); } KeyValues pkvSubKey = new KeyValues(newData); _keys.Add(pkvSubKey); iStart = GetFirstBracket(); _bHasParsedFully = true; } // Parse the rest, which is supposed to be non subkeys: for (int i = 0; i < _internalData.Count; i++) { _bHasParsedFully = true; KeyValueItem item; item.key = GetKeyFromLine(_internalData[i]); item.value = GetValueFromLine(_internalData[i]); _items.Add(item); } // No keys or sub keys were found!! if (!_bHasParsedFully) { LoggingUtils.LogEvent("Unable to parse sub-keys for KeyValues!"); } }
public static List <string> ReadFileToList(string filePath) { try { using (StreamReader sr = new StreamReader(filePath)) { List <string> fileLines = new List <string>(); while (!sr.EndOfStream) { fileLines.Add(sr.ReadLine()); } return(fileLines); } } catch { LoggingUtils.LogEvent(string.Format("Unable to read file '{0}' for KeyValues!", filePath)); return(null); } }
public static List <string> ReadStreamToList(string stream) { try { using (StringReader sr = new StringReader(stream)) { List <string> fileLines = new List <string>(); string line; while ((line = sr.ReadLine()) != null) { fileLines.Add(line); } return(fileLines); } } catch { LoggingUtils.LogEvent("Unable to read stream for KeyValues!"); return(null); } }
public bool ImportDependenciesToPath(string path) { if (!ParseQCFile(true)) { return(false); } if (_dependentFiles.Count() <= 0) { return(false); } try { string qcDir = Path.GetDirectoryName(_path); string relativeSubDir = Path.GetFileNameWithoutExtension(_path); for (int i = 0; i < _dependentFiles.Count(); i++) { string source = _dependentFiles[i]; string relativePath = Path.GetDirectoryName(source.Replace(qcDir, "")); string outputFile = string.Format("{0}\\{1}{2}\\{3}", path, relativeSubDir, relativePath, Path.GetFileName(source)); Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); File.Copy(source, outputFile, true); } File.WriteAllText(string.Format("{0}\\{1}", path, Path.GetFileName(_path)), GetQCContent(), Encoding.ASCII); } catch { LoggingUtils.LogEvent(string.Format("Unable to import anims, includes and references for QC {0} at path {1}!", Path.GetFileName(_path), Path.GetDirectoryName(_path))); return(false); } return(true); }
private void Initialize() { _items = new List <KeyValueItem>(); _keys = new List <KeyValues>(); bool bCouldParse = true; int indexFirst = GetFirstBracket(); if (indexFirst != -1) { _name = GetKeyFromLine(_internalData[indexFirst]); _internalData.RemoveRange(indexFirst, 2); // Remove the first key and bracket. int indexLast = GetLastBracket(0, true); if (indexLast != -1) { _internalData.RemoveAt(indexLast); // Remove the last bracket. } else { bCouldParse = false; } } else { bCouldParse = false; } if (!bCouldParse) { LoggingUtils.LogEvent("Unable to parse KeyValues! Fauly brackets..."); return; } ParseData(); }
private void btnAddFile_Click(object sender, EventArgs e) { string fileName = textBoxName.Text; string path = fileName; if (File.Exists(fileName)) { path = string.Format("{0}\\{1}", _filter.GetFilterDirectory(), Path.GetFileName(fileName)); QCParser importedQC = new QCParser(fileName); if (!importedQC.ImportDependenciesToPath(string.Format("{0}\\{1}", ProjectUtils.GetProjectDirectory(), Path.GetDirectoryName(path)))) { try { File.Copy(fileName, string.Format("{0}\\{1}", ProjectUtils.GetProjectDirectory(), path), true); } catch { LoggingUtils.LogEvent("Failed to import a file!"); } } } else { if (!Globals.IsStringValid(fileName)) { return; } path = string.Format("{0}\\{1}", _filter.GetFilterDirectory(), fileName); } if (!fileName.EndsWith(".qc", StringComparison.InvariantCultureIgnoreCase) && !fileName.EndsWith(".qci", StringComparison.InvariantCultureIgnoreCase)) { InfoDialog.ShowDialog(this, "Invalid file extension!", "Error!"); return; } string hasFile = ProjectUtils.GetFilePathForTreeNodeItem(_filter.GetName(), Path.GetFileName(path)); if (!string.IsNullOrEmpty(hasFile)) { InfoDialog.ShowDialog(this, "This file already exists in the choosen filter!", "Error!"); return; } string fullPath = string.Format("{0}\\{1}", ProjectUtils.GetProjectDirectory(), path); if (!File.Exists(fullPath)) { Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); File.WriteAllText(fullPath, ""); } _filter.AddFile("local", path); TreeNode newNode = new TreeNode(Path.GetFileName(path)); newNode.ContextMenuStrip = _fileStrip; newNode.ImageIndex = newNode.SelectedImageIndex = newNode.StateImageIndex = 0; _node.Nodes.Add(newNode); _node.ExpandAll(); Close(); }