public static GetDirectoryFileList ( string directory, string fileMask ) : string[] | ||
directory | string | |
fileMask | string | |
리턴 | string[] |
private void DeleteAnyExistingSplitResourceFiles() { foreach (string fileName in Utilities.GetDirectoryFileList(AGSEditor.OUTPUT_DIRECTORY, Factory.AGSEditor.BaseGameFileName + ".0*")) { File.Delete(fileName); } }
private void DeleteAnyExistingSplitResourceFiles() { foreach (string fileName in Utilities.GetDirectoryFileList(GetCompiledPath(), Factory.AGSEditor.BaseGameFileName + ".0*")) { File.Delete(fileName); } }
public override bool Build(CompileMessages errors, bool forceRebuild) { if (!base.Build(errors, forceRebuild)) { return(false); } string compiledDataDir = Path.Combine(AGSEditor.OUTPUT_DIRECTORY, AGSEditor.DATA_OUTPUT_DIRECTORY); string baseGameFileName = Factory.AGSEditor.BaseGameFileName; string newExeName = GetCompiledPath(baseGameFileName + ".exe"); string sourceEXE = Path.Combine(Factory.AGSEditor.EditorDirectory, AGSEditor.ENGINE_EXE_FILE_NAME); File.Copy(sourceEXE, newExeName, true); UpdateWindowsEXE(newExeName, errors); CreateCompiledSetupProgram(); Environment.CurrentDirectory = Factory.AGSEditor.CurrentGame.DirectoryPath; foreach (string fileName in Utilities.GetDirectoryFileList(compiledDataDir, "*")) { // TODO: this attributes check was added as a part of a hotfix. // Constructing a list of game files for distribution package // should be shared between build targets and done in a more // elaborate way. if ((File.GetAttributes(fileName) & (FileAttributes.Hidden | FileAttributes.System | FileAttributes.Temporary)) != 0) { continue; } if (fileName.EndsWith(".ags")) { using (FileStream ostream = File.Open(GetCompiledPath(baseGameFileName + ".exe"), FileMode.Append, FileAccess.Write)) { long startPosition = ostream.Position; using (FileStream istream = File.Open(fileName, FileMode.Open, FileAccess.Read)) { const int bufferSize = 4096; byte[] buffer = new byte[bufferSize]; for (int count = istream.Read(buffer, 0, bufferSize); count > 0; count = istream.Read(buffer, 0, bufferSize)) { ostream.Write(buffer, 0, count); } } // TODO: use functions shared with DataFileWriter // write the offset into the EXE where the first data file resides ostream.Write(BitConverter.GetBytes(startPosition), 0, 8); // write the CLIB end signature so the engine knows this is a valid EXE ostream.Write(Encoding.UTF8.GetBytes(DataFileWriter.CLIB_END_SIGNATURE.ToCharArray()), 0, DataFileWriter.CLIB_END_SIGNATURE.Length); } } else if (!fileName.EndsWith(AGSEditor.CONFIG_FILE_NAME)) { Utilities.HardlinkOrCopy(GetCompiledPath(Path.GetFileName(fileName)), fileName, true); } } // Update config file with current game parameters Factory.AGSEditor.WriteConfigFile(GetCompiledPath()); // Copy Windows plugins CopyPlugins(errors); return(true); }
public override bool Build(CompileMessages errors, bool forceRebuild) { if (!base.Build(errors, forceRebuild)) { return(false); } string compiledDir = AGSEditor.OUTPUT_DIRECTORY; string baseGameFileName = Factory.AGSEditor.BaseGameFileName; string newExeName = GetCompiledPath(baseGameFileName + ".exe"); string sourceEXE = Path.Combine(Factory.AGSEditor.EditorDirectory, AGSEditor.ENGINE_EXE_FILE_NAME); File.Copy(sourceEXE, newExeName, true); UpdateWindowsEXE(newExeName, errors); CreateCompiledSetupProgram(); Environment.CurrentDirectory = Factory.AGSEditor.CurrentGame.DirectoryPath; foreach (string fileName in Utilities.GetDirectoryFileList(compiledDir, "*")) { if (fileName.EndsWith(".ags")) { using (FileStream ostream = File.Open(GetCompiledPath(baseGameFileName + ".exe"), FileMode.Append, FileAccess.Write)) { int startPosition = (int)ostream.Position; using (FileStream istream = File.Open(fileName, FileMode.Open, FileAccess.Read)) { const int bufferSize = 4096; byte[] buffer = new byte[bufferSize]; for (int count = istream.Read(buffer, 0, bufferSize); count > 0; count = istream.Read(buffer, 0, bufferSize)) { ostream.Write(buffer, 0, count); } } // write the offset into the EXE where the first data file resides ostream.Write(BitConverter.GetBytes(startPosition), 0, 4); // write the CLIB end signature so the engine knows this is a valid EXE ostream.Write(Encoding.UTF8.GetBytes(NativeConstants.CLIB_END_SIGNATURE.ToCharArray()), 0, NativeConstants.CLIB_END_SIGNATURE.Length); } } else if (!fileName.EndsWith(AGSEditor.CONFIG_FILE_NAME)) { Utilities.CreateHardLink(GetCompiledPath(Path.GetFileName(fileName)), fileName, true); } } // Update config file with current game parameters Factory.AGSEditor.WriteConfigFile(GetCompiledPath()); // Copy Windows plugins CopyPlugins(errors); return(true); }
private object MakeBackupCopyOfGameFolderThread(object backupLocationAsObject) { string backupLocation = (string)backupLocationAsObject; string sourceDir = Path.GetDirectoryName(backupLocation); string[] fileNames = Utilities.GetDirectoryFileList(sourceDir, "*", SearchOption.AllDirectories); foreach (string file in fileNames) { string destinationFile = backupLocation + file.Substring(sourceDir.Length); string destinationDirectory = Path.GetDirectoryName(destinationFile); if (!Directory.Exists(destinationDirectory)) { Directory.CreateDirectory(destinationDirectory); } File.Copy(file, destinationFile); } return(null); }
/// <summary> /// Sets security permissions for all files in a directory. /// </summary> public static void SetDirectoryFilesAccess(string directory, SecurityIdentifier sid, FileSystemRights rights, AccessControlType type) { try { // first we will attempt to take ownership of the file // this ensures (if successful) that all users can change security // permissions for the file without admin access ProcessStartInfo si = new ProcessStartInfo("cmd.exe"); si.RedirectStandardInput = false; si.RedirectStandardOutput = false; si.RedirectStandardError = false; si.UseShellExecute = false; si.Arguments = string.Format("/c takeown /f \"{0}\" /r /d y", directory); si.CreateNoWindow = true; si.WindowStyle = ProcessWindowStyle.Hidden; if (Utilities.IsMonoRunning()) { si.FileName = "chown"; si.Arguments = string.Format("-R $USER:$USER \"{0}\"", directory); } Process process = Process.Start(si); bool result = (process != null); if (result) { process.EnableRaisingEvents = true; process.WaitForExit(); if (process.ExitCode != 0) { return; } process.Close(); // after successfully gaining ownership, parse each file in the // directory (recursively) and update its access rights foreach (string filename in Utilities.GetDirectoryFileList(directory, "*", SearchOption.AllDirectories)) { Utilities.SetFileAccess(filename, sid, rights, type); } } } catch (UnauthorizedAccessException) { } }
/// <summary> /// Gathers a list of files that could potentially be a part of the game. /// Skips main game data (*.ags) and config (these are treated separately). /// Returns an array of file paths. /// </summary> private List <string> GetAuxiliaryGameFiles(string sourcePath) { List <string> files = new List <string>(); foreach (string fileName in Utilities.GetDirectoryFileList(sourcePath, "*")) { // TODO: this attributes check was added as a part of a hotfix. // Constructing a list of game files for distribution package // should be shared between build targets and done in a more // elaborate way. if ((File.GetAttributes(fileName) & (FileAttributes.Hidden | FileAttributes.System | FileAttributes.Temporary)) != 0) { continue; } if (fileName.EndsWith(".ags") || fileName.EndsWith(AGSEditor.CONFIG_FILE_NAME)) { continue; } files.Add(fileName); } return(files); }