Ejemplo n.º 1
0
        static void Main()
        {
#if RELEASE
            try {
#endif
//		  System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ml-IN");
//		  System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ml-IN");

            // The application should be run in full trust mode; but just in case!
            System.Security.Permissions.EnvironmentPermission envPermission = new System.Security.Permissions.EnvironmentPermission(System.Security.Permissions.PermissionState.Unrestricted);
            envPermission.Demand();

            LoadRuntimeData();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
#if RELEASE
        }
        catch (Exception ex) {
            System.Security.Permissions.FileIOPermission ioperm = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.AllAccess, System.Security.AccessControl.AccessControlActions.Change, Utility.DEBUG_FILE_PATH);
            ioperm.Demand();
            using (FileStream fs = new FileStream(Utility.DEBUG_FILE_PATH, FileMode.Append, FileAccess.Write, FileShare.None)) {
                string debugMessage = "-------------------------------------------" + Environment.NewLine;
                debugMessage += DateTime.UtcNow.ToLongDateString() + " " + DateTime.UtcNow.ToLongTimeString() + " UTC" + Environment.NewLine + Environment.NewLine;
                debugMessage += ex.Message + Environment.NewLine;
                debugMessage += ex.StackTrace + Environment.NewLine + Environment.NewLine;
                byte[] buffer = System.Text.UTF8Encoding.UTF8.GetBytes(debugMessage);
                fs.Write(buffer, 0, buffer.Length);
                fs.Flush();
            }
            MessageBox.Show("An unhandled error has occured in SMOz. SMOz cannot continue.\n\nMore information is available in the file '" + Utility.DEBUG_FILE_PATH + "'. Please include the contents of that file when requesting support. Sorry about the inconvenience.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
#endif
        }
Ejemplo n.º 2
0
        private void yesBtn_Click(object sender, EventArgs e)
        {
            try
            {
                XmlDocument xDoc = new XmlDocument();
                //string sourceFilePath = string.Format("{0}{1}{2}{3}{4}{5}{6}", Environment.Is64BitOperatingSystem ? Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), System.IO.Path.DirectorySeparatorChar, "bLoyal", System.IO.Path.DirectorySeparatorChar, "Dinerware Integration", System.IO.Path.DirectorySeparatorChar, "DinerwareConfigurationFile.xml");
                //if (!System.IO.File.Exists(sourceFilePath))
                //    sourceFilePath = string.Format("{0}{1}{2}{3}{4}{5}{6}", Environment.Is64BitOperatingSystem ? Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), System.IO.Path.DirectorySeparatorChar, "bLoyal", System.IO.Path.DirectorySeparatorChar, "Workstation", System.IO.Path.DirectorySeparatorChar, "DinerwareConfigurationFile.xml");
                var    configuration  = new ConfigurationHelper(true);
                string sourceFilePath = configuration.GetFilePath();

                xDoc.Load(@"" + sourceFilePath);
                xDoc.DocumentElement.SelectSingleNode("EnablebLoyal").InnerText = "true";
                var permissionSet   = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
                var writePermission = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write, @"" + sourceFilePath);
                permissionSet.AddPermission(writePermission);
                if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
                {
                    xDoc.Save(@"" + sourceFilePath);
                }
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "yesBtn_Click");
                this.Close();
            }
            var config = ConfigurationHelper.NewInstance; // Update the Configuration Instance

            this.Close();
        }
Ejemplo n.º 3
0
        private Boolean CanSystemAccessFile()
        {
            //////////////////////////////////////////
            var perm = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write | System.Security.Permissions.FileIOPermissionAccess.Read, _st_PathErrLog);

            //
            try
            {
                perm.Demand();
                return(true);
            }
            catch (System.AccessViolationException ex_0)
            {
                return(false);
            }
            catch (IOException e)
            {
                if (IsSystemFileLocked(e))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex_1)
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        private void CheckFileAccess()
        {
            FileSecurity fs = System.IO.File.GetAccessControl(_path);

            FileInfo fi = new FileInfo(_path);

            System.Security.Permissions.FileIOPermission fp = new System.Security.Permissions.FileIOPermission
                                                                  (System.Security.Permissions.FileIOPermissionAccess.Read, _path);
            if (System.Security.SecurityManager.IsGranted(fp))
            {
                string tempPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + fi.Name;
                File.Copy(_path, tempPath, true);
                _path = tempPath;
            }
        }
Ejemplo n.º 5
0
 public static void SetPermissions()
 {
     //System.Security.Permissions.FileIOPermission f2 = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Read, "D:/David/AQUARELLA SQL/Sistema/Vb C# 2013/ELECTRONICO/Sistema/www.aquarella.com.pe/Sistema Aquarella/bin/Debug/exalib.dll");
     //f2.AddPathList(System.Security.Permissions.FileIOPermissionAccess.Write | System.Security.Permissions.FileIOPermissionAccess.Read, "D:/David/AQUARELLA SQL/Sistema/Vb C# 2013/ELECTRONICO/Sistema/www.aquarella.com.pe/Sistema Aquarella/bin/Debug/exalib.dll");
     try
     {
         System.Security.Permissions.FileIOPermission filePerm = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Read, "D:/David/AQUARELLA SQL/Sistema/Vb C# 2013/ELECTRONICO/Sistema/www.aquarella.com.pe/Sistema Aquarella/bin/Debug/exalib.dll");
         filePerm.Assert();
         //filePerm.Demand();
     }
     catch (System.Security.SecurityException s)
     {
         Console.WriteLine(s.Message);
     }
 }
Ejemplo n.º 6
0
 private string performFileSearchTask(string dirName, string strfileName)
 {
     try
     {
         if (strPG_dumpPath.Length == 0)
         {
             try
             {
                 foreach (string ddir in Directory.GetDirectories(dirName))
                 {
                     System.Security.Permissions.FileIOPermission ReadPermission =
                         new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write, ddir);
                     if (System.Security.SecurityManager.IsGranted(ReadPermission))
                     {
                         try
                         {
                             foreach (string dfile in Directory.GetFiles(ddir, strfileName))
                             {
                                 strPG_dumpPath = ddir + "\\";
                                 if (strPG_dumpPath.Length > 0)
                                 {
                                     strInstallLocation = strPG_dumpPath;
                                     break;
                                 }
                             }
                             if (strPG_dumpPath.Length == 0)
                             {
                                 performFileSearchTask(ddir, strfileName);
                             }
                         }
                         catch (Exception ex)
                         { }
                     }
                     if (strPG_dumpPath != string.Empty)
                     {
                         break;
                     }
                 }
             }
             catch (Exception ex)
             { }
         }
     }
     catch (Exception ex)
     { }
     return(strPG_dumpPath);
 }
Ejemplo n.º 7
0
        } // end checkForToSProcess

        internal static bool checkForToSDirectory(string tosRootDir)
        {
            bool ret = false;

            if (!string.IsNullOrEmpty(tosRootDir) && System.IO.Directory.Exists(tosRootDir))
            {
                System.Security.Permissions.FileIOPermission fP = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Read, tosRootDir);
                fP.AddPathList(System.Security.Permissions.FileIOPermissionAccess.Write | System.Security.Permissions.FileIOPermissionAccess.Read, tosRootDir);
                try {
                    fP.Demand();
                    ret = true;
                } catch (System.Security.SecurityException ex) {
                    Common.showError("Invalid access to directory", ex);
                }
            }
            return(ret);
        } // end checkForToSDirectory
Ejemplo n.º 8
0
 /// <summary>Determines whether a file is in use.</summary>
 ///<param name="filename">The path of the file.</param>
 /// <returns>
 /// Returns <c>true</c> if file is in use; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsFileInUse(string filename)
 {
     {
         var perm = new System.Security.Permissions.FileIOPermission(
             System.Security.Permissions.FileIOPermissionAccess.Write |
             System.Security.Permissions.FileIOPermissionAccess.Read,
             filename);
         try
         {
             perm.Demand();
             return(false);
         }
         catch
         {
             return(true);
         }
     }
 }
Ejemplo n.º 9
0
 /// <summary>Determines whether a file is in use.</summary>
 ///<param name="filename">The path of the file.</param>
 /// <returns>
 /// Returns <c>true</c> if file is in use; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsFileInUse(string filename)
 {
     {
         var perm = new System.Security.Permissions.FileIOPermission(
              System.Security.Permissions.FileIOPermissionAccess.Write |
              System.Security.Permissions.FileIOPermissionAccess.Read,
              filename);
         try
         {
             perm.Demand();
             return false;
         }
         catch
         {
             return true;
         }
     }
 }
Ejemplo n.º 10
0
 private void yesBtn_Click(object sender, EventArgs e)
 {
     try
     {
         XmlDocument xDoc           = new XmlDocument();
         string      sourceFilePath = string.Format("{0}{1}{2}{3}{4}{5}{6}", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), System.IO.Path.DirectorySeparatorChar, "bLoyal", System.IO.Path.DirectorySeparatorChar, "Dinerware Integration", System.IO.Path.DirectorySeparatorChar, "DinerwareConfigurationFile.xml");
         xDoc.Load(@"" + sourceFilePath);
         xDoc.DocumentElement.SelectSingleNode("EnablebLoyal").InnerText = "true";
         var    permissionSet    = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
         string sourceFolderPath = string.Format("{0}{1}{2}{3}{4}", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), System.IO.Path.DirectorySeparatorChar, "bLoyal", System.IO.Path.DirectorySeparatorChar, "Dinerware Integration");
         var    writePermission  = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write, @"" + sourceFolderPath);
         permissionSet.AddPermission(writePermission);
         if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
         {
             xDoc.Save(@"" + sourceFilePath);
         }
     }
     catch (Exception ex)
     {
     }
     this.Close();
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Create output file which is reversed image of the input file.
        /// </summary>
        /// <remarks>
        /// Does not use in memory reversal.
        /// Works on XXL files.
        /// Output file attributes will be stripped of. It will not be hidden, read only or system file.
        /// </remarks>
        /// <param name="input">file name or path</param>
        /// <param name="output">file name or path</param>
        public static void reverse( string input, string output )
        {
            input = Path.GetFullPath(input);
            output = Path.GetFullPath(output);
            if (!File.Exists(input)) throw new ArgumentException(string.Format("Input file {0}, not found?", input), input);

            // use if having this problem :
            // Exception:  System.UnauthorizedAccessException: Access to the path { output path here }is denied..
            System.Security.Permissions.FileIOPermission filePermission =
                new System.Security.Permissions.FileIOPermission(
                    System.Security.Permissions.FileIOPermissionAccess.AllAccess, output);
            filePermission.AllLocalFiles = System.Security.Permissions.FileIOPermissionAccess.AllAccess;
            filePermission.Assert();
            // Exception:  System.UnauthorizedAccessException: Access to the path { output path here }is denied..
            File.Copy(input, output, true);
            // clear all file attributes
            File.SetAttributes(output, FileAttributes.Normal);
            // Open the output for read and write
            using (FileStream fileStream = new FileStream(output, FileMode.Open))
            {
                Reverser.reverse(fileStream);
            }
        }
Ejemplo n.º 12
0
 private bool FileReadAllowed(string path)
 {
     var fp = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write, path);
     try
     {
         fp.Assert();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
Ejemplo n.º 13
0
        private string performFileSearchTask(string dirName, string strfileName)
        {
            try
            {
                if (strPG_dumpPath.Length == 0)
                {
                    try
                    {

                        foreach (string ddir in Directory.GetDirectories(dirName))
                        {
                            System.Security.Permissions.FileIOPermission ReadPermission =
                                new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write, ddir);
                            if (System.Security.SecurityManager.IsGranted(ReadPermission))
                            {
                                try
                                {
                                    foreach (string dfile in Directory.GetFiles(ddir, strfileName))
                                    {
                                        strPG_dumpPath = ddir + "\\";
                                        if (strPG_dumpPath.Length > 0)
                                        {
                                            strInstallLocation = strPG_dumpPath;
                                            break;
                                        }
                                    }
                                    if (strPG_dumpPath.Length == 0)
                                        performFileSearchTask(ddir, strfileName);
                                }
                                catch (Exception ex)
                                { }
                            }
                            if (strPG_dumpPath != string.Empty)
                                break;
                        }
                    }
                    catch (Exception ex)
                    { }

                }

            }
            catch (Exception ex)
            { }
            return strPG_dumpPath;
        }