AGS.Editor.Utilities.CreateHardLink C# (CSharp) Метод

CreateHardLink() публичный статический Метод

public static CreateHardLink ( string destFileName, string sourceFileName, bool overwrite ) : bool
destFileName string
sourceFileName string
overwrite bool
Результат bool
        public static bool CreateHardLink(string destFileName, string sourceFileName, bool overwrite)
        {
            if (File.Exists(destFileName))
            {
                if (overwrite) File.Delete(destFileName);
                else return false;
            }
            char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
            if (Path.GetFileName(destFileName).IndexOfAny(invalidFileNameChars) != -1)
            {
                throw new ArgumentException("Cannot create hard link! Invalid destination file name. (" + destFileName + ")");
            }
            if (Path.GetFileName(sourceFileName).IndexOfAny(invalidFileNameChars) != -1)
            {
                throw new ArgumentException("Cannot create hard link! Invalid source file name. (" + sourceFileName + ")");
            }
            if (!File.Exists(sourceFileName))
            {
                throw new FileNotFoundException("Cannot create hard link! Source file does not exist. (" + sourceFileName + ")");
            }
            ProcessStartInfo si = new ProcessStartInfo("cmd.exe");
            si.RedirectStandardInput = false;
            si.RedirectStandardOutput = false;
            si.RedirectStandardError = false;
            si.UseShellExecute = false;
            si.Arguments = string.Format("/c mklink /h \"{0}\" \"{1}\"", destFileName, sourceFileName);
            si.CreateNoWindow = true;
            si.WindowStyle = ProcessWindowStyle.Hidden;
            if ((!IsWindowsVistaOrHigher()) && (IsWindowsXPOrHigher())) // running Windows XP
            {
                si.Arguments = string.Format("/c fsutil hardlink create \"{0}\" \"{1}\"", destFileName, sourceFileName);
            }
            if (IsMonoRunning())
            {
                si.FileName = "ln";
                si.Arguments = string.Format("\"{0}\" \"{1}\"", sourceFileName, destFileName);
            }
            Process process = Process.Start(si);
            bool result = (process != null);
            if (result)
            {
                process.EnableRaisingEvents = true;
                process.WaitForExit();
                if (process.ExitCode != 0) return false;
                process.Close();
            }
            return result;
        }

Same methods

Utilities::CreateHardLink ( string destFileName, string sourceFileName ) : bool

Usage Example

Пример #1
0
        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);
        }
All Usage Examples Of AGS.Editor.Utilities::CreateHardLink