예제 #1
0
        public static Stream OpenFile(string path, OpenFileMode openFileMode)
        {
            if (openFileMode != 0 && openFileMode != OpenFileMode.ReadWrite && openFileMode != OpenFileMode.Create && openFileMode != OpenFileMode.CreateOrOpen)
            {
                throw new ArgumentException("openFileMode");
            }
            bool   isApp;
            string text = ProcessPath(path, openFileMode != OpenFileMode.Read, failIfApp: false, out isApp);

            if (isApp)
            {
                return(EngineActivity.m_activity.ApplicationContext.Assets.Open(text));
            }
            FileMode mode;

            switch (openFileMode)
            {
            case OpenFileMode.Create:
                mode = FileMode.Create;
                break;

            case OpenFileMode.CreateOrOpen:
                mode = FileMode.OpenOrCreate;
                break;

            default:
                mode = FileMode.Open;
                break;
            }
            FileAccess access = (openFileMode == OpenFileMode.Read) ? FileAccess.Read : FileAccess.ReadWrite;

            return(File.Open(text, mode, access, FileShare.Read));
        }
예제 #2
0
        public Stream OpenFile(string path, OpenFileMode mode)
        {
            if (mode == OpenFileMode.Read)
            {
                return(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read));
            }

            return(File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None));
        }
예제 #3
0
        /// <summary>
        /// Opens the file at the specified location for read or read/write.
        /// </summary>
        /// <param name="path">Path to file.</param>
        /// <param name="mode">Whether to open the file for reading or read/write</param>
        /// <returns>
        /// Stream to read/write to the file, null if file not found.
        /// </returns>
        public Stream OpenFile(string path, OpenFileMode mode)
        {
            var info = GetFileInfo(path);

            if (info == null || info.IsDirectory)
            {
                return(null);
            }

            return(new BundleReadStream(_fileName, info.Offset, info.Size, _fileSystem));
        }
예제 #4
0
        /// <summary>
        /// Opens the file at the specified location for read or read/write.
        /// </summary>
        /// <param name="path">Path to file.</param>
        /// <param name="mode">Whether to open the file for reading or read/write</param>
        /// <returns>
        /// Stream to read/write to the file, null if file not found.
        /// </returns>
        public Stream OpenFile(string path, OpenFileMode mode)
        {
            string fullPath = GetFullPath(path);

            if (_fileSystem.FileExists(fullPath))
            {
                return(_fileSystem.OpenFile(fullPath, mode));
            }

            return(Bundle.OpenFile(path, mode));
        }
        public OpenFileDialogView(IDialogFactory dialogFactory, LocLocalizer localizer, OpenFileMode filemode)
        {
            _dialogFactory = dialogFactory;
            _localizer     = localizer;
            _filemode      = filemode;
            InitializeComponent();

            if (filemode == OpenFileMode.OpenNewFile)
            {
                Title += _localizer.OpenFileDialogViewHeaderNewPrefix;
            }
        }
예제 #6
0
        public override Stream OpenFile(string name, OpenFileMode mode)
        {
            if (mode != OpenFileMode.Create)
            {
                throw new NotImplementedException();
            }

            string entryName = name.Replace('\\', '/');
            var    newEntry  = _zipFile.CreateEntry(entryName, _level);

            return(newEntry.Open());
        }
예제 #7
0
        public override Stream OpenFile(string name, OpenFileMode mode)
        {
            if (mode != OpenFileMode.Open)
            {
                throw new NotImplementedException();
            }

            var entry = _zipFile.GetEntry(name.Replace('\\', '/'));

            if (entry == null)
            {
                throw new FileNotFoundException("Cannot find file in zip archive.", name);
            }

            return(entry.Open());
        }
        public override Stream OpenFile(string name, OpenFileMode mode)
        {
            switch (mode)
            {
            case OpenFileMode.Create:
                return(Task.Run(() => _storage.OpenStreamForWriteAsync(name, CreationCollisionOption.ReplaceExisting).Result).Result);

            case OpenFileMode.Open:
                return(Task.Run(() => _storage.OpenStreamForReadAsync(name)).Result);

            case OpenFileMode.Append:
                return(Task.Run(() => _storage.OpenStreamForWriteAsync(name, CreationCollisionOption.OpenIfExists)).Result);
            }


            throw new NotImplementedException();
        }
예제 #9
0
        static public T Get <T>(string filepath, OpenFileMode mode, int bufferSize)
            where T : ClusteredFile, new()
        {
            var fi = new System.IO.FileInfo(filepath);

            // in case the file is readonly we assume users expect us to force the OpenReadOnly mode.
            if (fi.Exists && (fi.Attributes & FileAttributes.ReadOnly) != 0)
            {
                mode = OpenFileMode.OpenReadOnly;
            }
            ClusteredFile clusteredFile = null;

            if (!mOpenFiles.TryGetValue(fi.FullName, out clusteredFile))
            {
                clusteredFile = new T();
                mOpenFiles.Add(fi.FullName, clusteredFile);
            }
            FileMode   fm;
            FileAccess fa;
            FileShare  fs;

            switch (mode)
            {
            case OpenFileMode.OpenOrCreate:
                fm = FileMode.OpenOrCreate;
                fa = FileAccess.ReadWrite;
                fs = FileShare.Read;
                break;

            case OpenFileMode.OpenReadOnly:
                fm = FileMode.Open;
                fa = FileAccess.Read;
                fs = FileShare.ReadWrite;
                break;

            default:     // OpenFileMode.OpenReadWrite:
                fm = FileMode.Open;
                fa = FileAccess.ReadWrite;
                fs = FileShare.Read;
                break;
            }
            clusteredFile.InternalAddReader(fi, fm, fa, fs, bufferSize);
            return((T)clusteredFile);
        }
예제 #10
0
        public override Stream OpenFile(string name, OpenFileMode mode)
        {
            FileMode fileMode = FileMode.Open;

            switch (mode)
            {
            case OpenFileMode.Create:
                fileMode = FileMode.Create;
                break;

            case OpenFileMode.Append:
                fileMode = FileMode.Append;
                break;
            }

            Stream result = _storage.OpenFile(name, fileMode);

            return(result);
        }
예제 #11
0
파일: FileData.cs 프로젝트: dox0/uTrade
        public FileData(string name, OpenFileMode mode, char delimiter, FileAccess fileAccess, FileStream fs)
        {
            this.FileName   = name;
            this.Mode       = mode;
            this.Delimiter  = delimiter;
            this.FileAccess = fileAccess;
            this.FileStream = fs;
            bool flag = (this.Mode & OpenFileMode.FILE_CSV) == OpenFileMode.FILE_CSV;

            if (flag)
            {
                bool canRead = fs.CanRead;
                if (canRead)
                {
                    this.SReader = new StreamReader(fs);
                }
                bool canWrite = fs.CanWrite;
                if (canWrite)
                {
                    this.SWriter = new StreamWriter(fs);
                }
                this.IsBinary = false;
            }
            else
            {
                bool canRead2 = fs.CanRead;
                if (canRead2)
                {
                    this.Reader = new BinaryReader(fs);
                }
                bool canWrite2 = fs.CanWrite;
                if (canWrite2)
                {
                    this.Writer = new BinaryWriter(fs);
                }
                this.IsBinary = true;
            }
        }
예제 #12
0
 public static extern int LZOpenFileW([MarshalAs(UnmanagedType.LPWStr)] StringBuilder param0,
                                      ref OFStruct param1, OpenFileMode param2);
예제 #13
0
 /// <summary>
 /// Creates, opens, reopens, or deletes the specified file
 /// </summary>
 /// <param name="lpFileName">The name of the file</param>
 /// <param name="lpReOpenBuf">A pointer to the OFSTRUCT structure that is to receive information about the
 /// file when the file is first opened. The structure can be used in subsequent calls to the LZOpenFile
 /// function to see the open file</param>
 /// <param name="wStyle">The action to be taken</param>
 /// <returns>If the function succeeds and the value specified by the wStyle parameter is not OF_READ, the
 /// return value is a handle identifying the file. If the file is compressed and opened with wStyle set to
 /// OF_READ, the return value is a special file handle</returns>
 /// <remarks>If the function fails, the return value is an LZERROR_* code. Use the LZError enum to map the error code.
 /// These codes have values less than zero. There is no extended error information for this function;
 /// DO NOT call GetLastError.</remarks>
 public static int LZOpenFile(StringBuilder lpFileName, ref OFStruct lpReOpenBuf, OpenFileMode wStyle)
 {
     return(Environment.OSVersion.Platform >= PlatformID.Win32NT ? Native.LZOpenFileW(lpFileName, ref lpReOpenBuf, wStyle) : Native.LZOpenFileA(lpFileName, ref lpReOpenBuf, wStyle));
 }
 public SourceSelected(string?source, OpenFileMode mode)
 {
     Source = source;
     Mode   = mode;
 }
 public static Func <SourceSelected> From(Func <string?> data, OpenFileMode mode)
 => () => new SourceSelected(data(), mode);
예제 #16
0
 public virtual Stream OpenFile(string name, OpenFileMode mode)
 {
     return(null);
 }
예제 #17
0
 public static extern nn.Result Open(
     ref FileHandle outValue, string path, OpenFileMode mode);
예제 #18
0
        private ServiceResult Open(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            OpenFileMode mode,
            TrustListMasks masks,
            ref uint fileHandle)
        {
            HasSecureReadAccess(context);

            if (mode == OpenFileMode.Read)
            {
                HasSecureReadAccess(context);
            }
            else if (mode == (OpenFileMode.Write | OpenFileMode.EraseExisting))
            {
                HasSecureWriteAccess(context);
            }
            else
            {
                return(StatusCodes.BadNotWritable);
            }

            lock (m_lock)
            {
                if (m_sessionId != null)
                {
                    // to avoid deadlocks, last open always wins
                    m_sessionId            = null;
                    m_strm                 = null;
                    m_node.OpenCount.Value = 0;
                }

                m_readMode  = mode == OpenFileMode.Read;
                m_sessionId = context.SessionId;
                fileHandle  = ++m_fileHandle;

                TrustListDataType trustList = new TrustListDataType()
                {
                    SpecifiedLists = (uint)masks
                };

                using (ICertificateStore store = CertificateStoreIdentifier.OpenStore(m_trustedStorePath))
                {
                    if ((masks & TrustListMasks.TrustedCertificates) != 0)
                    {
                        X509Certificate2Collection certificates = store.Enumerate().Result;
                        foreach (var certificate in certificates)
                        {
                            trustList.TrustedCertificates.Add(certificate.RawData);
                        }
                    }

                    if ((masks & TrustListMasks.TrustedCrls) != 0)
                    {
                        foreach (var crl in store.EnumerateCRLs())
                        {
                            trustList.TrustedCrls.Add(crl.RawData);
                        }
                    }
                }

                using (ICertificateStore store = CertificateStoreIdentifier.OpenStore(m_issuerStorePath))
                {
                    if ((masks & TrustListMasks.IssuerCertificates) != 0)
                    {
                        X509Certificate2Collection certificates = store.Enumerate().Result;
                        foreach (var certificate in certificates)
                        {
                            trustList.IssuerCertificates.Add(certificate.RawData);
                        }
                    }

                    if ((masks & TrustListMasks.IssuerCrls) != 0)
                    {
                        foreach (var crl in store.EnumerateCRLs())
                        {
                            trustList.IssuerCrls.Add(crl.RawData);
                        }
                    }
                }

                if (m_readMode)
                {
                    m_strm = EncodeTrustListData(context, trustList);
                }
                else
                {
                    m_strm = new MemoryStream(DefaultTrustListCapacity);
                }

                m_node.OpenCount.Value = 1;
            }

            return(ServiceResult.Good);
        }
예제 #19
0
 public static extern Result Rename(string currentPath, string newPath);                                                           // 0x00A15AC0-0x00A15B20
 public static extern Result Open(ref FileHandle outValue, string path, OpenFileMode mode);                                        // 0x00A15B20-0x00A15B80
예제 #20
0
 public Stream Open(OpenFileMode mode, OpenFileAccess access, OpenFileShare share)
 {
     return(FileInfo.Open((FileMode)mode, (FileAccess)access, (FileShare)share));
 }
예제 #21
0
파일: Win32.cs 프로젝트: tmpkus/openvss
 public static extern int AVIFileOpen(
     out IntPtr ppfile,
     String szFile,
     OpenFileMode mode,
     IntPtr pclsidHandler);
예제 #22
0
 public static extern int AVIFileOpen(
     out IntPtr aviHandler,
     String fileName,
     OpenFileMode mode,
     IntPtr handler);
예제 #23
0
 /// <summary>
 /// Creates, opens, reopens, or deletes the specified file
 /// </summary>
 /// <param name="lpFileName">The name of the file</param>
 /// <param name="lpReOpenBuf">A pointer to the OFSTRUCT structure that is to receive information about the
 /// file when the file is first opened. The structure can be used in subsequent calls to the LZOpenFile 
 /// function to see the open file</param>
 /// <param name="wStyle">The action to be taken</param>
 /// <returns>If the function succeeds and the value specified by the wStyle parameter is not OF_READ, the
 /// return value is a handle identifying the file. If the file is compressed and opened with wStyle set to
 /// OF_READ, the return value is a special file handle</returns>
 /// <remarks>If the function fails, the return value is an LZERROR_* code. Use the LZError enum to map the error code.
 /// These codes have values less than zero. There is no extended error information for this function;
 /// DO NOT call GetLastError.</remarks>
 public static int LZOpenFile(StringBuilder lpFileName, ref OFStruct lpReOpenBuf, OpenFileMode wStyle)
 {
     return Environment.OSVersion.Platform >= PlatformID.Win32NT ? Native.LZOpenFileW(lpFileName, ref lpReOpenBuf, wStyle) : Native.LZOpenFileA(lpFileName, ref lpReOpenBuf, wStyle);
 }
예제 #24
0
 public static extern int LZOpenFileW([MarshalAs(UnmanagedType.LPWStr)] StringBuilder param0,
     ref OFStruct param1, OpenFileMode param2);
예제 #25
0
        private bool _OpenFile2(string filename, out PlayerData playerData, OpenFileMode mode)
        {
            UInt32 calcMinTick = ~0u;

            playerData = new PlayerData();

            byte[] buff = null;

            FileInfo fi = new FileInfo(filename);

            try
            {
                WorkingDir = fi.DirectoryName;
                Filename   = fi.Name;
            }
            catch (Exception e)
            {
                Logs.Write("Failed to get working folder");
                return(false);
            }

            buff = File.ReadAllBytes(filename);
            if (mode == OpenFileMode.OnlineDecrypt)
            {
                buff = DecryptDataOnline(buff);
            }

            if (buff == null)
            {
                return(false);
            }

            ByteArrayStream stream = new ByteArrayStream(buff);

            string sign = stream.ReadString(4);

            if (sign != "PTFF")
            {
                return(false);
            }

            byte   version       = stream.ReadByte();
            byte   un            = stream.ReadByte();
            UInt16 tickPerMinute = stream.ReadUShort();
            float  tempo2        = stream.ReadFloat();
            UInt16 tracksCount   = stream.ReadUShort();
            UInt32 headerEndTick = stream.ReadUInt();
            float  trackDuration = stream.ReadFloat();

            Logs.Write(String.Format("tmp : {0}", tickPerMinute));
            Logs.Write(String.Format("tempo2 : {0}", tempo2));
            Logs.Write(String.Format("tracksCount : {0}", tracksCount));
            Logs.Write(String.Format("headerEndTick : {0}", headerEndTick));
            Logs.Write(String.Format("trackDuration : {0}", trackDuration));

            playerData.Version       = version;
            playerData.TrackDuration = trackDuration;
            playerData.TickPerMinute = tickPerMinute;
            playerData.Tempo         = tempo2;
            playerData.HeaderEndTick = headerEndTick;


            //Logs.Write("version : {0}", version);

            stream.Seek(0x16);
            ushort insCnt = stream.ReadUShort();

            stream.Seek(0x18);

            playerData.Clear();

            playerData.Instruments.Add(new InstrumentData()
            {
                InsNum = 0,
                Name   = "none"
            });

            // read ogg instruments list
            for (int i = 0; i < insCnt; i++)
            {
                ushort insNo    = 0;
                UInt16 unknown1 = 0;
                UInt16 unknown2 = 0;
                if (version == 1)
                {
                    insNo    = stream.ReadUShort();
                    unknown1 = stream.ReadByte();
                    unknown2 = stream.ReadByte();
                }
                else
                {
                    insNo    = stream.ReadByte();
                    unknown1 = stream.ReadByte();
                }

                if (insNo > 1000)
                {
                    Logs.Write("sound count over 1000");
                    return(false);
                }

                string oggName = stream.ReadString(0x40);

                Logs.Write("insNo : {0} - {1}; op: {2}, {3}", insNo, oggName, unknown1, unknown2);

                playerData.Instruments.Add(new InstrumentData()
                {
                    InsNum = insNo,
                    Name   = oggName
                });
            }

            uint eventIndex = 0;
            uint trackIndex = 0;

            while (true)
            {
                if (stream.Available < 4)
                {
                    break;
                }

                uint eztr = stream.ReadUInt();
                if (eztr != EZTR)
                {
                    Logs.Write("invalid Magic");
                    return(false);

                    break;
                }
                ;

                stream.Skip(0x02);

                string trackName = stream.ReadString(0x40);

                uint endTick   = stream.ReadUInt();
                int  blockSize = stream.ReadInt();

                if (version == 1)
                {
                    ushort un1 = stream.ReadUShort();
                }

                int eventSize = version == 1 ? 0x10 : 0x0B;

                int eventsCount = (int)(double)(blockSize / eventSize);

                TrackData track = new TrackData(trackIndex)
                {
                    TrackName = trackName
                };

                playerData.Tracks.AddTrack(track);

                for (int i = 0; i < eventsCount; i++)
                {
                    int  tick = stream.ReadInt();
                    byte id   = stream.ReadByte();

                    if (version == 1)
                    {
                        byte[] extraData = stream.ReadBytes(0xB);


                        switch ((EventType)id)
                        {
                        case EventType.None:
                            Logs.Write("NULL event");
                            break;

                        case EventType.Note:
                        {
                            ushort insNo = BitConverter.ToUInt16(extraData, 3);
                            byte   vel   = extraData[5];
                            byte   pan   = extraData[6];

                            byte   attribute = extraData[7];
                            ushort duration  = BitConverter.ToUInt16(extraData, 8);

                            /*
                             * Logs.Write(String.Format(
                             *  "Note 0x0 : {0, 3}; 0x1: {1, 3}; 0x2: {2, 3}; insNo: {3, 10}; vel: {4, 3}; pan: {5, 3}; attribute: {6, 3}; duration: {7, 10}; 0xA: {8, 3}",
                             *  extraData[0x0],
                             *  extraData[0x1],
                             *  extraData[0x2],
                             *
                             *  insNo, // insNo
                             *
                             *  extraData[0x5], // vel
                             *  extraData[0x6], // pan
                             *  extraData[0x7], // attribute
                             *
                             *  duration, // duration
                             *
                             *  extraData[0xA]
                             * ));*/


                            InstrumentData inst =
                                playerData.Instruments.SingleOrDefault(ins => ins.InsNum == insNo);

                            EventData newEvent = new EventData()
                            {
                                TrackId    = trackIndex,
                                Tick       = tick,
                                Attribute  = attribute,
                                Duration   = duration,
                                EventType  = EventType.Note,
                                Instrument = inst,
                                Vel        = vel,
                                Pan        = pan
                            };

                            track.AddEvent(newEvent);

                            eventIndex++;
                            calcMinTick = (UInt32)Math.Min(calcMinTick, tick);         // debug purpose
                        }
                        break;

                        case EventType.Volume:
                        {
                            byte volume = extraData[3];

                            EventData newEvent = new EventData()
                            {
                                TrackId   = trackIndex,
                                Tick      = tick,
                                EventType = EventType.Volume,
                                Volume    = volume
                            };

                            track.AddEvent(newEvent);

                            eventIndex++;
                        }
                        break;

                        case EventType.Tempo:
                        {
                            float tempo = BitConverter.ToSingle(extraData, 3);

                            EventData newEvent = new EventData()
                            {
                                TrackId   = trackIndex,
                                Tick      = tick,
                                EventType = EventType.Tempo,
                                Tempo     = tempo
                            };

                            track.AddEvent(newEvent);

                            eventIndex++;
                        }
                        break;

                        case EventType.Beat:
                        {
                            ushort beat = BitConverter.ToUInt16(extraData, 3);

                            EventData newEvent = new EventData()
                            {
                                TrackId   = trackIndex,
                                Tick      = tick,
                                EventType = EventType.Beat,
                                Beat      = beat
                            };

                            track.AddEvent(newEvent);

                            eventIndex++;
                        }
                        break;

                        default:
                            Logs.Write("Unknow event : {0}", id);
                            break;
                        }
                    }
                    else
                    {
                        byte[] extraData = stream.ReadBytes(0x6);

                        switch ((EventType)id)
                        {
                        case EventType.None:
                            Logs.Write("NULL event");
                            break;

                        case EventType.Note:
                        {
                            byte insNo = extraData[0];
                            byte vel   = extraData[1];
                            byte pan   = extraData[2];

                            byte   attribute = extraData[3];
                            ushort duration  = BitConverter.ToUInt16(extraData, 4);

                            InstrumentData inst =
                                playerData.Instruments.FirstOrDefault(ins => ins != null && ins.InsNum == insNo);

                            EventData newEvent = new EventData()
                            {
                                TrackId    = trackIndex,
                                Tick       = tick,
                                Attribute  = attribute,
                                Duration   = duration,
                                EventType  = EventType.Note,
                                Instrument = inst,
                                Vel        = vel,
                                Pan        = pan
                            };

                            track.AddEvent(newEvent);

                            eventIndex++;
                        }
                        break;

                        case EventType.Volume:
                        {
                            byte volume = extraData[0];

                            EventData newEvent = new EventData()
                            {
                                //TrackId = trackIndex,
                                Tick      = tick,
                                EventType = EventType.Volume,
                                Volume    = volume
                            };

                            track.AddEvent(newEvent);

                            eventIndex++;
                        }
                        break;

                        case EventType.Tempo:
                        {
                            float tempo = BitConverter.ToSingle(extraData, 0);

                            EventData newEvent = new EventData()
                            {
                                TrackId   = trackIndex,
                                Tick      = tick,
                                EventType = EventType.Tempo,
                                Tempo     = tempo
                            };

                            track.AddEvent(newEvent);

                            eventIndex++;
                        }
                        break;

                        case EventType.Beat:
                        {
                            ushort beat = BitConverter.ToUInt16(extraData, 0);

                            EventData newEvent = new EventData()
                            {
                                TrackId   = trackIndex,
                                Tick      = tick,
                                EventType = EventType.Beat,
                                Beat      = beat
                            };

                            track.AddEvent(newEvent);

                            eventIndex++;
                        }
                        break;

                        default:
                            Logs.Write("Unknow event : {0}", id);
                            break;
                        }
                    }
                }

                trackIndex++;
            }

            stream.Dispose();

            foreach (TrackData track in playerData.Tracks)
            {
                int minTick = 0, maxTick = 0;
                if (track.Events.Count() > 0)
                {
                    minTick = track.Events.Min(evnt => evnt.Tick);
                    maxTick = track.Events.Max(evnt => evnt.Tick);
                }

                int len = maxTick - minTick;
            }

            playerData.Encrypted = mode == OpenFileMode.OnlineDecrypt;

            return(true);
        }