Ejemplo n.º 1
0
        private void Open()
        {
            if (listBox1.SelectedItem == null)
            {
                return;
            }

            var stream = listBox1.SelectedItem as NtfsAlternateStream;

            if (stream == null)
            {
                return;
            }


            OpenOrSave   form         = new OpenOrSave();
            DialogResult dialogResult = form.ShowDialog();

            if (dialogResult != DialogResult.OK && dialogResult != DialogResult.Yes)
            {
                return;
            }

            if (form.OpenSave == OpenSave.Open)
            {
                string   text     = NtfsAlternateStream.ReadAllText(_path + stream.Name);
                TextView textView = new TextView(text);
                textView.Show();
            }
            else if (form.OpenSave == OpenSave.Save)
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.FileName = ConvertUtilities.ToFileName(stream.Name);
                DialogResult showDialog = dialog.ShowDialog();
                if (showDialog != DialogResult.OK && showDialog != DialogResult.Yes)
                {
                    return;
                }

                using (var dstStream = dialog.OpenFile())
                {
                    using (var srcStream = NtfsAlternateStream.Open(_path + stream.Name, FileAccess.Read, FileMode.Open, FileShare.Read))
                    {
                        srcStream.CopyTo(dstStream);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //get tags file content
        private string getFileStream(string fileName) //brings the stream the ads read the ads of the file
        {
            if (checkTagFileExists(fileName))         //if there is a tag
            {
                string     streamName = ":fileTags";
                FileStream stream     = NtfsAlternateStream.Open(fileName + streamName, FileAccess.ReadWrite, FileMode.OpenOrCreate, FileShare.None); //open the ads
                stream.Close();
                IEnumerable <NtfsAlternateStream> fileStream = NtfsAlternateStream.EnumerateStreams(fileName);                                        //bring all the ads the file has whats in the stream
                foreach (NtfsAlternateStream ads in fileStream)                                                                                       //enter the filestream
                {
                    if (ads.StreamType.ToString().Equals("AlternateData"))
                    {
                        if (ads.Name.Equals(streamName + ":$DATA"))             //type of ads

                        {
                            return(Regex.Replace(NtfsAlternateStream.ReadAllText(fileName + streamName), "\n|\r", ""));
                        }
                    }
                }
            }

            return("The file doesn't have tags");
        }