Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Graphics files stumper...

Graphics files stumper...

Scheduled Pinned Locked Moved C#
graphicstutorialquestion
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    new_phoenix
    wrote on last edited by
    #1

    Is there any way of preventing graphics files from being overwritten by an end user even when the application is not running? In Windows 2000 and above when you right-click on a graphics file, there is a folder tab which contains the potential to add information about the graphics file. While there is not any PASSWORD field available, could this information perhaps be used to prevent the files from being overwritten by the end user. Say, for example that these files were important enough to need protection. Would some sort of run-time windows interface file be needed to prevent the files from being overwritten? Any suggestions for an approach to protect the graphics files that could be turned ON and turned OFF again when needed by the application?

    C C C 3 Replies Last reply
    0
    • N new_phoenix

      Is there any way of preventing graphics files from being overwritten by an end user even when the application is not running? In Windows 2000 and above when you right-click on a graphics file, there is a folder tab which contains the potential to add information about the graphics file. While there is not any PASSWORD field available, could this information perhaps be used to prevent the files from being overwritten by the end user. Say, for example that these files were important enough to need protection. Would some sort of run-time windows interface file be needed to prevent the files from being overwritten? Any suggestions for an approach to protect the graphics files that could be turned ON and turned OFF again when needed by the application?

      C Offline
      C Offline
      cobyjone
      wrote on last edited by
      #2

      You could change the attributes on the file to make it a system and hidden file when you are not using it. Users shouldn't even be able to see the file then. Then, when you need to change the file, just remove the attributes(if that is necessary, you may just be able to edit the file without removing the attributes) and put them back after your done. System.IO.FileInfo file = new System.IO.FileInfo(fileName); if ((file.Attributes & System.IO.FileAttributes.Hidden) != 1) { file.Attributes &= System.IO.FileAttributes.Hidden; } if ((file.Attributes & System.IO.FileAttributes.System) != 1) { file.Attributes &= System.IO.FileAttributes.System; } //Modify File file.Attributes |= System.IO.FileAttributes.Hidden; file.Attributes |= System.IO.FileAttributes.System;

      N 1 Reply Last reply
      0
      • N new_phoenix

        Is there any way of preventing graphics files from being overwritten by an end user even when the application is not running? In Windows 2000 and above when you right-click on a graphics file, there is a folder tab which contains the potential to add information about the graphics file. While there is not any PASSWORD field available, could this information perhaps be used to prevent the files from being overwritten by the end user. Say, for example that these files were important enough to need protection. Would some sort of run-time windows interface file be needed to prevent the files from being overwritten? Any suggestions for an approach to protect the graphics files that could be turned ON and turned OFF again when needed by the application?

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Embed them as a resource in your application. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

        N 1 Reply Last reply
        0
        • N new_phoenix

          Is there any way of preventing graphics files from being overwritten by an end user even when the application is not running? In Windows 2000 and above when you right-click on a graphics file, there is a folder tab which contains the potential to add information about the graphics file. While there is not any PASSWORD field available, could this information perhaps be used to prevent the files from being overwritten by the end user. Say, for example that these files were important enough to need protection. Would some sort of run-time windows interface file be needed to prevent the files from being overwritten? Any suggestions for an approach to protect the graphics files that could be turned ON and turned OFF again when needed by the application?

          C Offline
          C Offline
          Corinna John
          wrote on last edited by
          #4

          (1) The application does not change the graphics. Try Christian Graus' solution. (2) The application changes the graphics. Change the filenames, so that the user does not recognise them as graphics files. If that's not possible, save a backup of the files everytime the application is being closed (in /data/important.dat, or something like that). On next start, check last modification time and, if the backups are older than the original, restore the backups. (3) The application won't crash with different images, you just don't like them to get changed. Embed a watermark in the graphics, and try to extract it whenever the application starts. Refuse to run, if the watermark is not okay. _________________________________ Vote '1' if you're too lazy for a discussion

          N 1 Reply Last reply
          0
          • C Christian Graus

            Embed them as a resource in your application. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

            N Offline
            N Offline
            new_phoenix
            wrote on last edited by
            #5

            Not certain what embedding as a resource means exactly. However, I would need to be able to overwrite them when more current files are available. If I embedded them as a binary file somehow, if that is what you mean, could that be overwritten utilizing a binary writer in System.IO.BinaryWriter, or something? I need to be able to have the user overwrite the files when properly interacting with the application, but I do not want the user to be able to overwrite the graphics files while the program is not running. Otherwise, the user could set the graphics to something that is an unintended usage for the program. Meaning, I do not want undesirable graphic files overwriting the intended graphic files for the application. Could you kindly enlighten me about what you mean by embedding it as a resource. I would appreciate it. Thanks :~

            C 1 Reply Last reply
            0
            • C Corinna John

              (1) The application does not change the graphics. Try Christian Graus' solution. (2) The application changes the graphics. Change the filenames, so that the user does not recognise them as graphics files. If that's not possible, save a backup of the files everytime the application is being closed (in /data/important.dat, or something like that). On next start, check last modification time and, if the backups are older than the original, restore the backups. (3) The application won't crash with different images, you just don't like them to get changed. Embed a watermark in the graphics, and try to extract it whenever the application starts. Refuse to run, if the watermark is not okay. _________________________________ Vote '1' if you're too lazy for a discussion

              N Offline
              N Offline
              new_phoenix
              wrote on last edited by
              #6

              Not certain exactly how to embed a watermark in a .gif file. Isn't a .gif file the equivalent of a raster graphics file, while a watermark would require something like a vector-based photoshop file so that the watermark could be somehow extracted and compared to some text value? Also, I would need to be able to overwrite them when more current files are available. I like the idea of changing the properties of the files to readonly, system and hidden that smbecker had suggested, but then I would need to also be able to hide the folder in which the files are stored. If I embedded them as a binary file somehow, if that is what you mean, could that be overwritten utilizing a binary writer in System.IO.BinaryWriter, or something? I need to be able to have the user overwrite the files when properly interacting with the application, but I do not want the user to be able to overwrite the graphics files while the program is not running. Otherwise, the user could set the graphics to something that is an unintended usage for the program. Could you kindly enlighten me about how to store the graphic files in a .dat file that could be overwritten by the application when the user interacts with the program properly? I also need to be able to prevent the user from deleting the folder or the files entirely so some interaction with the O/S is necessary via the System.IO.FileAttributes.System interface which restricts what the user can do with files. Also, with above Windows 2000, graphic files when right-clicked have permissions provided, could C# interface with these properties and change those when the application interacts with them properly when running? To see what I mean, simple right-click on a graphics file when using above Windows 2000. Could these permissions be interfaced with as well as utilizing the .Hidden and .System and .ReadOnly attributes of FileAttributes? I seriously doubt that an end user would know that they would be required to not only find the file folder, then the files, then change the attributes of the files, and then change the permission to the files provided by right clicking on them. Would these steps be enough to protect the graphic files? I would appreciate more assistance. Thanks :~

              S C 2 Replies Last reply
              0
              • N new_phoenix

                Not certain what embedding as a resource means exactly. However, I would need to be able to overwrite them when more current files are available. If I embedded them as a binary file somehow, if that is what you mean, could that be overwritten utilizing a binary writer in System.IO.BinaryWriter, or something? I need to be able to have the user overwrite the files when properly interacting with the application, but I do not want the user to be able to overwrite the graphics files while the program is not running. Otherwise, the user could set the graphics to something that is an unintended usage for the program. Meaning, I do not want undesirable graphic files overwriting the intended graphic files for the application. Could you kindly enlighten me about what you mean by embedding it as a resource. I would appreciate it. Thanks :~

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                It means that you make the file part of the project, and then select 'embed as resource' from the properties for the file. This means the file is part of the exe, and loaded from the exe, but it therefore means you cannot edit it. Now that I understand the problem, I'd recommend some sort of digital signature on your images, so that you can reject images that don't fit it. There are articles on embedding a string in an image on this site, that's probably how I'd go. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

                1 Reply Last reply
                0
                • N new_phoenix

                  Not certain exactly how to embed a watermark in a .gif file. Isn't a .gif file the equivalent of a raster graphics file, while a watermark would require something like a vector-based photoshop file so that the watermark could be somehow extracted and compared to some text value? Also, I would need to be able to overwrite them when more current files are available. I like the idea of changing the properties of the files to readonly, system and hidden that smbecker had suggested, but then I would need to also be able to hide the folder in which the files are stored. If I embedded them as a binary file somehow, if that is what you mean, could that be overwritten utilizing a binary writer in System.IO.BinaryWriter, or something? I need to be able to have the user overwrite the files when properly interacting with the application, but I do not want the user to be able to overwrite the graphics files while the program is not running. Otherwise, the user could set the graphics to something that is an unintended usage for the program. Could you kindly enlighten me about how to store the graphic files in a .dat file that could be overwritten by the application when the user interacts with the program properly? I also need to be able to prevent the user from deleting the folder or the files entirely so some interaction with the O/S is necessary via the System.IO.FileAttributes.System interface which restricts what the user can do with files. Also, with above Windows 2000, graphic files when right-clicked have permissions provided, could C# interface with these properties and change those when the application interacts with them properly when running? To see what I mean, simple right-click on a graphics file when using above Windows 2000. Could these permissions be interfaced with as well as utilizing the .Hidden and .System and .ReadOnly attributes of FileAttributes? I seriously doubt that an end user would know that they would be required to not only find the file folder, then the files, then change the attributes of the files, and then change the permission to the files provided by right clicking on them. Would these steps be enough to protect the graphic files? I would appreciate more assistance. Thanks :~

                  S Offline
                  S Offline
                  Skynyrd
                  wrote on last edited by
                  #8

                  There is no way to prevent a user if he's really set on it to modify a file when the application thats supposed to gaurd it is not running. Not even marking it as readonly/systemfile/hidden really works if the user knows where to look. However, u can make the task as hard as u can. Some ideas could be (many more possibilities but dont have the time to really think through all of them ;P ): 1)Change extension of files so the user or image viewing/editing applications dont recognize them as images. U could even encrypt the byte array so that even if the user is smart enough to recognize the files, he still wont be able to process the images. 2)Save them in "obscure folders" the user will normally not interact/look in: For example the user's Application Data folder in Documents and Settings 3)If the images are not really big u could even think about saving them into the registry as byte arrays (I think its possible)

                  1 Reply Last reply
                  0
                  • N new_phoenix

                    Not certain exactly how to embed a watermark in a .gif file. Isn't a .gif file the equivalent of a raster graphics file, while a watermark would require something like a vector-based photoshop file so that the watermark could be somehow extracted and compared to some text value? Also, I would need to be able to overwrite them when more current files are available. I like the idea of changing the properties of the files to readonly, system and hidden that smbecker had suggested, but then I would need to also be able to hide the folder in which the files are stored. If I embedded them as a binary file somehow, if that is what you mean, could that be overwritten utilizing a binary writer in System.IO.BinaryWriter, or something? I need to be able to have the user overwrite the files when properly interacting with the application, but I do not want the user to be able to overwrite the graphics files while the program is not running. Otherwise, the user could set the graphics to something that is an unintended usage for the program. Could you kindly enlighten me about how to store the graphic files in a .dat file that could be overwritten by the application when the user interacts with the program properly? I also need to be able to prevent the user from deleting the folder or the files entirely so some interaction with the O/S is necessary via the System.IO.FileAttributes.System interface which restricts what the user can do with files. Also, with above Windows 2000, graphic files when right-clicked have permissions provided, could C# interface with these properties and change those when the application interacts with them properly when running? To see what I mean, simple right-click on a graphics file when using above Windows 2000. Could these permissions be interfaced with as well as utilizing the .Hidden and .System and .ReadOnly attributes of FileAttributes? I seriously doubt that an end user would know that they would be required to not only find the file folder, then the files, then change the attributes of the files, and then change the permission to the files provided by right clicking on them. Would these steps be enough to protect the graphic files? I would appreciate more assistance. Thanks :~

                    C Offline
                    C Offline
                    Corinna John
                    wrote on last edited by
                    #9

                    new_phoenix wrote: Not certain exactly how to embed a watermark in a .gif file. You can embed a certain code in a .gif file, there are two different methods: (1) GIF Shuffle: Good for images with a palette of 256 colors, or very small watermarks. Google for it, there are several examples on the web. (2) Palette Stretching: Not perfect, but might be okay for images with a small palette, where GIF Shuffle could not embed enough bits. There's an article on CP.[^] how to store the graphic files in a .dat file Copy the file an rename it from *.gif to *.dat. ;) Users will need a while to find it. You can also encrypt the images when writing the .dat file. Search CP for Encrypted Streams, I think there is an example, too. _________________________________ Vote '1' if you're too lazy for a discussion

                    1 Reply Last reply
                    0
                    • C cobyjone

                      You could change the attributes on the file to make it a system and hidden file when you are not using it. Users shouldn't even be able to see the file then. Then, when you need to change the file, just remove the attributes(if that is necessary, you may just be able to edit the file without removing the attributes) and put them back after your done. System.IO.FileInfo file = new System.IO.FileInfo(fileName); if ((file.Attributes & System.IO.FileAttributes.Hidden) != 1) { file.Attributes &= System.IO.FileAttributes.Hidden; } if ((file.Attributes & System.IO.FileAttributes.System) != 1) { file.Attributes &= System.IO.FileAttributes.System; } //Modify File file.Attributes |= System.IO.FileAttributes.Hidden; file.Attributes |= System.IO.FileAttributes.System;

                      N Offline
                      N Offline
                      new_phoenix
                      wrote on last edited by
                      #10

                      smbecker: Attempted to utilize your code, but it appears that much of the code is written in C++. For example, the code: System.IO.FileInfo file = new System.IO.FileInfo(fileName); if ((file.Attributes & System.IO.FileAttributes.Hidden)!=1) { file.Attributes &= System.IO.FileAttributes.Hidden; } does not work, because the C# compiler does not understand != 1. More specifically, the error message I get is: "operator '!=' cannot be applied to operands of type 'System.IO.FileAttributes' and 'int'." I would also like to request a couple other clarifications. First, I suspect that the aforementioned code would act in the following manner. If a file is hidden, then unhide it so that the changes could be made. Make the changes to the file, and then hide it again. The same would be true for the other FileAttributes including System, and ReadOnly. I really like your thought processes in writing the code, but I do admit that I am at a loss to understand it. I did not come from the C++ environment, and I do not clearly understand the use of the &= , the |= or the !=1 construction in C# nor do I understand the logical AND statment before the !=1. Therefore, I would really appreciate it if you could write it another way. Also, I am not certain how the code in the if statements work to convert the files to their normal format (ie unhidden, nonsystem, and not readonly) so that changes could be made. Would really appreciate some further elaboration. :confused::confused: Thanks New_Phoenix

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups