Пример #1
0
 public void OnGetFileSize(SolFSStorage Sender, UInt32 File, ref UInt64 Size, ref int Result)
 {
     using (FileStream stream = (FileStream)FindStream(File))
     {
         Size   = (ulong)stream.Length;
         Result = 0;
     }
 }
Пример #2
0
 protected void Sample_DecryptData(SolFSStorage Sender, byte[] key, byte[] data, uint ObjectID, uint PageIndex, ref Int32 Result)
 {
     for (int i = 0; i < data.Length; i++)
     {
         data[i] ^= key[i % key.Length];
     }
     Result = 0;
 }
Пример #3
0
 protected void Sample_CalculateHash(SolFSStorage Sender, byte[] buffer, byte[] hashBuffer, ref Int32 Result)
 {
     Result = 0;
     for (int i = 0; i < hashBuffer.Length; i++)
     {
         hashBuffer[i] = 0;
     }
 }
Пример #4
0
 private void SetRegistration()
 {
     try
     {
         SolFSStorage.SetRegistrationKey(_RegKey);
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #5
0
 public void OnDeleteFile(SolFSStorage Sender, String FileName, ref int Result)
 {
     try
     {
         File.Delete(FileName);
     }
     catch (Exception)
     {
         Result = -1;
     }
 }
Пример #6
0
        public void OnOpenFile(SolFSStorage Sender, String FileName, ref UInt32 File, ref bool ReadOnly, bool IsJournalFile, ref int Result)
        {
            FileStream stream = null;

            try
            {
                try
                {
                    stream   = new FileStream(FileName, FileMode.Open, FileAccess.ReadWrite);
                    ReadOnly = false;
                    Result   = 0;
                }
                catch (FileNotFoundException)
                {
                    Result = 2;     //ERROR_FILE_NOT_FOUND
                }
                catch (UnauthorizedAccessException)
                {
                    Result = 5;
                }

                if (Result == 5)
                {
                    stream   = new FileStream(FileName, FileMode.Open, FileAccess.Read);
                    ReadOnly = true;
                    Result   = 0;
                }

                if (Result == 0)
                {
                    int hashcode = stream.GetHashCode();
                    if (hashcode < 0)
                    {
                        hashcode += 0x7fffffff;
                    }
                    File = (uint)hashcode;
                    StorageStreams.Add(File, stream);
                }
            }
            catch (Exception)
            {
                Result = -1;
                File   = 0xffffffff;
            }
            finally
            {
                stream.Close();
            }
        }
Пример #7
0
 public void OnWriteFile(SolFSStorage Sender, UInt32 File, byte[] buffer, UInt32 Count, ref int Result)
 {
     try
     {
         using (FileStream stream = (FileStream)FindStream(File))
         {
             stream.Write(buffer, 0, (int)Count);
             Result = 0;
         }
     }
     catch (Exception)
     {
         Result = Result = -1;
     }
 }
Пример #8
0
 public void OnSetFileSize(SolFSStorage Sender, UInt32 File, UInt64 NewSize, ref int Result)
 {
     try
     {
         using (FileStream stream = (FileStream)FindStream(File))
         {
             stream.SetLength((long)NewSize);
             Result = 0;
         }
     }
     catch (Exception)
     {
         Result = -1;
     }
 }
Пример #9
0
 public void OnFlushFile(SolFSStorage Sender, UInt32 File, ref int Result)
 {
     try
     {
         using (FileStream stream = (FileStream)FindStream(File))
         {
             stream.Flush();
             Result = 0;
         }
     }
     catch (Exception)
     {
         Result = -1;
     }
 }
Пример #10
0
        public void GetFiles()
        {
            string sRegKey = "C05B5ADAD4C53C9A3F988DBA5FBC119ED39B6FF6F71BC83C88FDAACFDF49665B37A61F3CF2B8C4B7272BDE8639E0F92981A03614C4DBD8CDFABF1C71FE649FF58878C3E7BF6E00DBE4C3752DFF23B299B7D8A5172FA71D4909CF618E48BD6A8F6C7CC8";

            try
            {
                SolFSStorage.SetRegistrationKey(sRegKey);
            }
            catch (Exception e)
            {
                //MessageBox.Show("Error happened while trying to set the license key");
                return;
            }

            //return null;
        }
Пример #11
0
        public void OnCloseFile(SolFSStorage Sender, ref UInt32 File, ref int Result)
        {
            using (FileStream stream = (FileStream)FindStream(File))
            {
                StorageStreams.Remove(File);
                try
                {
                    stream.Close();
                    Result = 0;
                }
                catch (Exception)
                {
                    Result = Result = -1;
                }

                File = 0xffffffff;
            }
        }
Пример #12
0
        public void OnCreateFile(SolFSStorage Sender, String FileName, ref UInt32 File, bool Overwrite, bool IsJournalFile, ref int Result)
        {
            FileStream stream = null;

            try
            {
                if (Overwrite)
                {
                    stream = new FileStream(FileName, FileMode.Create);
                    Result = 0;
                }
                else
                {
                    try
                    {
                        stream = new FileStream(FileName, FileMode.CreateNew);
                        Result = 0;
                    }
                    catch (IOException)
                    {
                        Result = 183; //ERROR_ALREADY_EXISTS
                    }
                }
                if (Result == 0)
                {
                    int hashcode = stream.GetHashCode();
                    if (hashcode < 0)
                    {
                        hashcode += 0x7fffffff;
                    }
                    File = (uint)hashcode;
                    StorageStreams.Add(File, stream);
                }
            }
            catch (Exception)
            {
                Result = -1;
                File   = 0xffffffff;
            }
            finally
            {
                stream.Close();
            }
        }
Пример #13
0
 public void OnReadFile(SolFSStorage Sender, UInt32 File, byte[] buffer, UInt32 Count, ref int Result)
 {
     try
     {
         using (FileStream stream = (FileStream)FindStream(File))
         {
             int read = stream.Read(buffer, 0, (int)Count);
             if (read == Count)
             {
                 Result = 0;
             }
             else
             {
                 Result = -1;
             }
         }
     }
     catch (Exception)
     {
         Result = Result = -1;
     }
 }
Пример #14
0
        public void OnSeekFile(SolFSStorage Sender, UInt32 File, Int64 Offset, UInt16 Origin, ref int Result)
        {
            SeekOrigin origin;

            switch (Origin)
            {
            case 0:
                origin = SeekOrigin.Begin;
                break;

            case 1:
                origin = SeekOrigin.Current;
                break;

            case 2:
                origin = SeekOrigin.End;
                break;

            default:
                origin = SeekOrigin.Begin;
                break;
            }

            try
            {
                using (FileStream stream = (FileStream)FindStream(File))
                {
                    stream.Seek(Offset, origin);
                    Result = 0;
                }
            }
            catch (Exception)
            {
                Result = -1;
            }
        }
Пример #15
0
 protected void Sample_ValidateHash(SolFSStorage Sender, byte[] buffer, byte[] hashBuffer, ref System.Boolean Valid, ref Int32 Result)
 {
     Result = 0;
     Valid  = true;
 }
Пример #16
0
        static void Main(string[] args)
        {
            var strRegKey = ConfigurationManager.AppSettings["RegistrationKey"];
            SolFSStorage.SetRegistrationKey(strRegKey);

            var mountFileName = ConfigurationManager.AppSettings["MountFileName"];
            mountFileName = (mountFileName.Length == 0) ? "SolFS001.img" : mountFileName;

            var strNextDriveLetter = getNextDriveLetter();
            if (strNextDriveLetter.Length == 0)
                throw new Exception("No Drive letter Available !");

            if (!IsDriverInitialized())
            {
                Console.WriteLine("Driver Not Installed ! \nInstalling Driver..");
                if (InstallDriver(_strDiskDriverFileName, _strFileSystemDriverName) == InstallStatus.RebootRequired)
                {
                    Console.WriteLine("Driver Installed. \nReboot Required. \nExiting..");
                    Environment.Exit(0);
                }
            }

            var storage = new SolFSStorage()
            {
                FileName = (args.Length == 0) ? mountFileName : args[0],
                DestroyOnProcessTerminated = true,
                PageSize = 32768,
                UseTransactions = true,
                UseAccessTime = true,
            };

            try
            {
                storage.Open((File.Exists(storage.FileName) ? StorageOpenMode.somOpenExisting : StorageOpenMode.somCreateNew));
                storage.AddMountingPoint(strNextDriveLetter + ":");
                storage.Logo = "SkyDrive";
                Console.WriteLine("Mounted " + storage.FileName + " to " + strNextDriveLetter + ":");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                storage.Close();
            }

            Console.WriteLine("Press Any Key to Exit.");
            Console.ReadKey();
            storage.Dispose();
        }