我应该如何存储用户指定的一组文件?
我正在编写一个新的 C# 桌面应用程序,该应用程序将允许用户选择应用程序需要记住的一组图像文件。我还需要保存一些其他设置,我打算将它们与它们指定的文件一起保存为 xml 文件。我正在考虑尝试将这些文件一起保存在 zip/cab 类型文件或类似的文件中,有点像 .war 或 .docx 文件。这样,当用户回来时,他们可以选择他们的文件并获得他们需要的一切。这样用户将无法(轻松)删除所需的文件。缺点是文件可能会变得相当大,特别是因为它可能包含图像文件。
但是,然后我在考虑 Visual Studio 如何将内容存储在其项目文件 (.cproj) 中,该文件是指向文件夹中特定文件的指针。这似乎也是一个不错的解决方案。按照这条路线,我必须添加更多错误检查以确保用户没有删除文件。我不确定这是否会超出压缩/解压缩文件所需的代码。
有什么指示可以更好吗?这两种方法都有优点/缺点吗?
I'm writing a new c# desktop application that is going to allow users to select a group of image files that the application requires to remember. I also have some other settings to save that I was going to save as an xml file along with the files they specify. I was thinking of trying to save the files together in a zip/cab type file or something similar, sort of like a .war or .docx file. That way when the user comes back, they can select their file and have everything they need. This way user's wouldn't be able to (easily) delete a needed file. Cons would be the file could get rather large, especially since it could contain image files.
But, then I was thinking of how visual studio stores things in their project files (.cproj) which is a pointer to specific files in a folder. This seems like a good solution also. Going this route, I'd have to add some more error checking to make sure the user didn't delete a file. I'm not sure if this would out way the code needed to zip/unzip the files though.
Any pointers on which way would be better? Any pros/cons to either method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题没有正确的答案,实际上取决于真正的业务需求是什么。要记住的最重要的事情之一是,如果您使用对文件位置的引用,则可以在应用程序在线和离线时在应用程序外部修改文件。如果这是一个导入功能,我会使用文件引用,如果您需要保留文件的快照,我会将它们放入压缩文件中。
There is not a right answer to this question an really depends on what the real business requirements are. One of the most important thing to remember is that if you use references to file locations files can be modified out side of your application while the application is both online and off line. If that is an import feature I would go with file refs if you need to keep a snap shot of the files i would put them in a compressed file.
嗯......当你正在考虑拥有一个 XML 文件时,我会考虑将图像数据保存为 XML 文件中的 CDATA 部分,由此可以重新创建它们(并且图像不会“丢失”)或“移动”)。
虽然这可能会导致 XML 文件相当大,但一旦它超过一定大小,您始终可以对其进行压缩(达到一定大小,压缩它不会有任何回报,解压缩它所需的时间可能比加载未压缩版本所需的时间)。
将其包含在 XML 文件中还消除了使用数据库进行存储的需要 - 尽管使用 SQLCompact 也可能是一个可行的选择(您可以将图像存储在数据库中)。
Hmmmm.... as you are looking at having an XML file anyway, i would look at saving the image data as a CDATA section in the XML file, from this they can be recreated (and the images won't get "lost" or "moved").
While this can lead to a rather large XML file, you can always zip it once it gets over a certain size (up to a certain size there will be no payback in zipping it, the time it takes to unzip it can be longer than the time it takes to load the uncompressed version).
Including it in the XML file also eliminates the need for using a database for storage - although using SQLCompact might also be a viable option (you can just store the image in the database).