Пример #1
0
        /// <summary>
        /// Deletes the temporary file
        /// </summary>
        /// <param name="tmpFile">FileStream to be deleted</param>
        private void DeleteTempFile(FileStream tmpFile)
        {
            if (SecureDelete.IsPossible())
            {
                string name = tmpFile.Name;
                tmpFile.Close();

                bool deleted = SecureDelete.DeleteFile(name, 5); //try secure deletion
                if (!deleted)
                {
                    File.Delete(name);
                }
            }
            else //if sdelete is not available
            {
                //Dispose temp file by overwriting with 0
                tmpFile.Position = 0;
                byte[] bytes  = new byte[16384];
                long   amount = (tmpFile.Length / bytes.Length + 1);

                for (long i = 0; i < amount; i++)
                {
                    tmpFile.Write(bytes, 0, bytes.Length);
                }

                string name = tmpFile.Name;
                tmpFile.Close();
                File.Delete(name);
            }
        }
Пример #2
0
        /// <summary>
        /// Closes a FileStream
        /// </summary>
        /// <param name="targetFile">FileStream to be closed</param>
        /// <param name="delete">Delete file afterwards</param>
        private void CloseTargetFile(FileStream targetFile, bool delete = false)
        {
            string path = targetFile.Name;

            targetFile.Close();

            if (delete)
            {
                bool deleted = SecureDelete.DeleteFile(path);
                if (!deleted)
                {
                    File.Delete(path);
                }
            }
        }