Пример #1
0
        public static bool CanIWrite(string inPath)
        {
            // this will return true if write or modify or take ownership or any of those other good perms are available.
            CurrentUserSecurity currentUserSecurity = new CurrentUserSecurity();

            FileSystemRights[] fsRights =
            {
                FileSystemRights.Write,
                FileSystemRights.Modify,
                FileSystemRights.FullControl,
                FileSystemRights.TakeOwnership,
                FileSystemRights.ChangePermissions,
                FileSystemRights.AppendData,
                FileSystemRights.CreateFiles,
                FileSystemRights.CreateDirectories,
                FileSystemRights.WriteData
            };

            FileAttributes attr       = File.GetAttributes(inPath);
            bool           writeRight = false;

            foreach (FileSystemRights fsRight in fsRights)
            {
                try
                {
                    if (attr.HasFlag(FileAttributes.Directory))
                    {
                        DirectoryInfo dirInfo = new DirectoryInfo(inPath);
                        if (currentUserSecurity.HasAccess(dirInfo, fsRight))
                        {
                            writeRight = true;
                        }
                    }
                    else
                    {
                        FileInfo fileInfo = new FileInfo(inPath);
                        if (currentUserSecurity.HasAccess(fileInfo, fsRight))
                        {
                            writeRight = true;
                        }
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    return(false);
                }
            }
            return(writeRight);
        }
Пример #2
0
        public static bool CanIRead(FileInfo fileInfo)
        {
            // this will return true if file read perm is available.
            var currentUserSecurity = new CurrentUserSecurity();

            FileSystemRights[] fsRights =
            {
                FileSystemRights.Read,
                FileSystemRights.ReadAndExecute,
                FileSystemRights.ReadData
            };

            var readRight = false;

            foreach (var fsRight in fsRights)
            {
                try
                {
                    if (currentUserSecurity.HasAccess(fileInfo, fsRight))
                    {
                        readRight = true;
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    return(false);
                }
            }

            return(readRight);
        }
Пример #3
0
        public static bool CanIWrite(FileInfo fileInfo)
        {
            // this will return true if write or modify or take ownership or any of those other good perms are available.
            var currentUserSecurity = new CurrentUserSecurity();

            FileSystemRights[] fsRights =
            {
                FileSystemRights.Write,
                FileSystemRights.Modify,
                FileSystemRights.FullControl,
                FileSystemRights.TakeOwnership,
                FileSystemRights.ChangePermissions,
                FileSystemRights.AppendData,
                FileSystemRights.WriteData
            };

            var writeRight = false;

            foreach (var fsRight in fsRights)
            {
                try
                {
                    if (currentUserSecurity.HasAccess(fileInfo, fsRight))
                    {
                        writeRight = true;
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    return(false);
                }
            }

            return(writeRight);
        }
Пример #4
0
        public static bool CanIRead(string inPath)
        {
            // this will return true if file read perm is available.
            CurrentUserSecurity currentUserSecurity = new CurrentUserSecurity();

            FileSystemRights[] fsRights =
            {
                FileSystemRights.Read,
                FileSystemRights.ReadAndExecute,
                FileSystemRights.ReadData
            };

            FileAttributes attr      = File.GetAttributes(inPath);
            bool           readRight = false;

            foreach (FileSystemRights fsRight in fsRights)
            {
                try
                {
                    if (attr.HasFlag(FileAttributes.Directory))
                    {
                        DirectoryInfo dirInfo = new DirectoryInfo(inPath);
                        if (currentUserSecurity.HasAccess(dirInfo, fsRight))
                        {
                            readRight = true;
                        }
                    }
                    else
                    {
                        FileInfo fileInfo = new FileInfo(inPath);
                        if (currentUserSecurity.HasAccess(fileInfo, fsRight))
                        {
                            readRight = true;
                        }
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    return(false);
                }
            }
            return(readRight);
        }
Пример #5
0
        private bool HasPermissions(string path)
        {
            CurrentUserSecurity user = new CurrentUserSecurity();

            return(user.HasAccess(new DirectoryInfo(path),
                                  FileSystemRights.ReadData | FileSystemRights.CreateDirectories
                                  | FileSystemRights.Traverse | FileSystemRights.Delete
                                  | FileSystemRights.ReadAndExecute | FileSystemRights.ReadData | FileSystemRights.Write));

            //no acces: FileSystemRights.DeleteSubdirectoriesAndFiles
        }
Пример #6
0
        private void CriaPasta(string PastaValida)
        {
            //Criamos um com o nome folder
            if (!Directory.Exists(PastaValida))
            {
                Directory.CreateDirectory(PastaValida);
            }

            if (!CurrentUserSecurity.HasAccess(new DirectoryInfo(PastaValida), System.Security.AccessControl.FileSystemRights.CreateDirectories))
            {
                MessageBox.Show("Sem permissão ao caminho " + PastaValida, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Пример #7
0
        private void backup()
        {
            try
            {
                // define o nome do arquivo de backup de acordo com a data e hora.
                string dia           = DateTime.Now.Day.ToString("00");
                string mes           = DateTime.Now.Month.ToString("00");
                string ano           = DateTime.Now.Year.ToString("0000");
                string hora          = DateTime.Now.ToLongTimeString().Replace(":", "");
                string nomeDoArquivo = ano + "_" + mes + "_" + dia + "_" + hora;

                string pasta = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory()) + "\\BACHUP";
                CriaPasta(pasta);
                if (!CurrentUserSecurity.HasAccess(new DirectoryInfo(pasta), System.Security.AccessControl.FileSystemRights.CreateDirectories))
                {
                    MessageBox.Show("Sem permissão ao caminho " + pasta, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string Arquivo = pasta + "\\" + nomeDoArquivo + ".sql";
                using (MySqlConnection conn = new MySqlConnection(new DadosDaConexao().getWebConfig("MySql")))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();

                            //mb.ExportInfo.EnableEncryption = true;
                            //mb.ExportInfo.EncryptionPassword = "******";
                            mb.ExportToFile(Arquivo);
                            conn.Close();
                            MessageBoxEx.Show("Cópia do banco de dados realizado com sucesso.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBoxEx.Show("Erro em criar o bachup.. preocure o adm" + ex.Message + " Caminho: " + ex.StackTrace);
            }
        }
Пример #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="folder"></param>
        void WriteSettings(string folder)
        {
            CurrentUserSecurity cs = new CurrentUserSecurity();

            if (cs.HasAccess(new FileInfo(Path.Combine(folder, "settings.bin")), System.Security.AccessControl.FileSystemRights.Write))
            {
                using (FileStream fn = new FileStream(Path.Combine(folder, "settings.bin"), FileMode.Open, FileAccess.ReadWrite))
                {
                    WriteByte(fn, coreSettingsOffsets[(int)CoreSettings.DebugGx2ApiOffset], settings.DebugGx2ApiOffset);
                    WriteByte(fn, coreSettingsOffsets[(int)CoreSettings.DebugUnsupportedApiCallsOffset], settings.DebugUnsupportedApiCallsOffset);
                    WriteByte(fn, coreSettingsOffsets[(int)CoreSettings.DebugThreadSynchronisationApiOffset], settings.DebugThreadSynchronisationApiOffset);
                    WriteByte(fn, coreSettingsOffsets[(int)CoreSettings.DebugAudioApiOffset], settings.DebugAudioApiOffset);
                    WriteByte(fn, coreSettingsOffsets[(int)CoreSettings.DebugInputApiOffset], settings.DebugInputApiOffset);

                    byte volume = settings.Volume;
                    if (model.Settings.UseGlobalVolumeSettings)
                    {
                        volume = (byte)model.Settings.GlobalVolume;
                    }

                    WriteByte(fn, coreSettingsOffsets[(int)CoreSettings.VolumeOffset], volume);
                    WriteByte(fn, coreSettingsOffsets[(int)CoreSettings.EnableDebugOffset], settings.EnableDebugOffset);
                    WriteByte(fn, coreSettingsOffsets[(int)CoreSettings.CpuModeOffset], (byte)settings.CpuMode);
                    WriteByte(fn, coreSettingsOffsets[(int)CoreSettings.CpuTimerOffset], (byte)settings.CpuTimer);

                    WriteByte(fn, settingsOffsets[(int)Settings.GpuBufferAccuractOffset], (byte)settings.GpuBufferCacheAccuracy);
                    WriteByte(fn, settingsOffsets[(int)Settings.UpscaleFilterOffset], (byte)settings.UpscaleFilter);
                    WriteByte(fn, settingsOffsets[(int)Settings.FullScreenScalingOffset], (byte)settings.FullScreenScaling);
                    WriteByte(fn, settingsOffsets[(int)Settings.VSyncOffset], settings.EnableVSync);

                    WriteByte(fn, settingsOffsets[(int)Settings.RenderUpsideDownOffset], settings.RenderUpsideDown);
                    WriteByte(fn, settingsOffsets[(int)Settings.DisableAudioOffset], settings.DisableAudio);
                    WriteByte(fn, settingsOffsets[(int)Settings.ConsoleRegionOffset], (byte)model.Settings.ConsoleRegion);
                    WriteByte(fn, settingsOffsets[(int)Settings.ConsoleLanguageOffset], (byte)model.Settings.ConsoleLanguage);
                    WriteByte(fn, settingsOffsets[(int)Settings.BoTwWorkAroundOffset], settings.EnableBoTwCrashWorkaround);
                    WriteByte(fn, settingsOffsets[(int)Settings.FullSyncAtGx2Offset], settings.FullSyncAtGx2DrawDone);
                    WriteByte(fn, settingsOffsets[(int)Settings.SeparateGamepadViewOffset], settings.SeparateGamePadView);
                    WriteByte(fn, settingsOffsets[(int)Settings.UseRtdscOffset], settings.UseRtdsc);
                    WriteByte(fn, settingsOffsets[(int)Settings.EnableOnLineModeOffset], settings.Online != 0 ? 3 : 2);
                }
            }
        }
Пример #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="file"></param>
 /// <param name="completeFileName"></param>
 internal static void ExtractFile(ZipArchiveEntry file, string completeFileName)
 {
     try
     {
         CurrentUserSecurity cs = new CurrentUserSecurity();
         if (File.Exists(completeFileName))
         {
             if (cs.HasAccess(new FileInfo(completeFileName), System.Security.AccessControl.FileSystemRights.Write))
             {
                 file.ExtractToFile(completeFileName, true);
             }
         }
         else
         {
             file.ExtractToFile(completeFileName, true);
         }
     }
     catch (System.Exception)
     {
         // ignored
     }
 }
Пример #10
0
        private void WriteGameProfile(string folder)
        {
            if (!Directory.Exists(Path.Combine(folder, "gameProfiles")))
            {
                Directory.CreateDirectory(Path.Combine(folder, "gameProfiles"));
            }

            CurrentUserSecurity cs = new CurrentUserSecurity();

            if (cs.HasAccess(new FileInfo(Path.Combine(folder, "gameProfiles", information.TitleId + ".ini")), System.Security.AccessControl.FileSystemRights.Write))
            {
                using (StreamWriter writer = new StreamWriter(Path.Combine(folder, "gameProfiles", information.TitleId + ".ini")))
                {
                    writer.WriteLine("[Graphics]");
                    writer.WriteLine("accurateShaderMul = " + (settings.AccaccurateShaderMul == 1 ? "true" : (settings.AccaccurateShaderMul == 0) ? "false" : "min"));
                    writer.WriteLine("disableGPUFence =  " + (settings.DisableGpuFence == 1 ? "true" : "false"));
                    writer.WriteLine("[CPU]");
                    writer.WriteLine("emulateSinglePrecision = " + (settings.EmulateSinglePrecision == 1 ? "true" : "false"));
                }
            }

            FileManager.GrantAccess(Path.Combine(folder, "gameProfiles", information.TitleId + ".ini"));
        }