C#如何使用浏览路径? [英] C# How to use a BROWSE for path?

查看:112
本文介绍了C#如何使用浏览路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在我的程序中,我最近收到了一些反馈.该程序使用新文件更新客户端游戏文件夹.

我安装了它,以便它找到文件,删除它们,然后复制新文件.一切都很好..

我现在只真正想到了人们有时会更改默认安装位置的事实...

所以现在我正在考虑如何解决这个问题.



我做了一个选择,他们可以在其中浏览他们的计算机并找到游戏文件夹.他们找到的位置显示在文本框EG中:

So with my program i have recently had some feedback. The program updates the clients game folder with new files.

I had it setup so it finds the files, deletes them then copys over the new files. All went well..

I have now only really thought about the fact that people sometimes change the default install location.....

So NOW i am thinking about how to accomplish such an issue.



I made a Option where they can browse their computer and find the game folder. The location they find is displayed in a textbox EG:

//Search For Gane Folder
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
{

}

private void button9_Click(object sender, EventArgs e)
{
    folderBrowserDialog1.ShowDialog();
    textBox1.Text = folderBrowserDialog1.SelectedPath;
}

private void Form1_Load(object sender, EventArgs e)
{
    textBox1.ReadOnly = true;
}



因此,我认为这是对的,它可以工作,等等.现在这是棘手的部分...它们是我可以做到的一种方法,因此在上面的文本框中选择的路径就是所使用的路径吗?

因此,如果他们选择游戏路径,则单击更新"按钮,它将删除TEXTBOX选定路径中的文件?

因此,他们使用BROWSE选择了安装路径,如果TEXTBOX中存在一个路径,则它将在以下位置使用TEXTBOXPATH:



So i think that is right it works etc. Now here is the tricky part... Is their a way i can make it so the path selected in the above textbox is the path used?

So if they select the game path then they click the UPDATE button and it deletes files in the TEXTBOX selected path?

So they choose the install path with BROWSE, If a path in TEXTBOX exists then it uses TEXTBOXPATH in this:

if (File.Exists(@"TEXTBOXPATH\Cool.inf"))
                        File.Delete(@"TEXTBOXPATH\Cool.inf");
                    File.Copy(@"C:\PROGRA~1\NEW PROGRAM\Cool.inf", @"TEXTBOXPATH\Cool,inf");




jsut还意识到这是否也意味着必须让他们指定程序文件路径?由于64位和32位不同....




Also jsut realised does this mean ill also have to have an option to ask them to specify the Program Files path? As 64bit and 32 are different....

推荐答案



嗯,首先,我想评论一下,用户必须在安装路径后浏览,这对用户来说不是很友好.
如果用户更新了游戏,我认为他们之前已经启动了一次未更新的游戏,因此您可以使用

Hi,

hm, first i want to comment it''s not very user friendly that users had to browse after the install path.
If users update the game, I assume they''ve started non-updated game once before, so you could use

string fullPath = System.Reflection.Assembly.GetAssembly(typeof("Someofyourassemblyname")).Location;



并将该路径保存到您的.inf文件之一或其他内容中.
对于有人安装您的游戏并在安装后立即运行更新的情况,您必须确保它在更新一次之前就已启动,但是我认为对于用户来说还可以,最坏的情况是编写一些执行该程序的HelperProgram安装后.

由于具有只读权限,在尝试删除文件并将其复制到ProgramFiles-Dir(程序文件和Program Files(x86))时也要格外小心.

如果您的软件不断增长,那么您将不得不编写自己的更新程序.
有一些可用的开源自动更新程序,例如:
http://autoupdater.codeplex.com/ [ ^ ]

使用(或Visual Studio安装项目,但不适用于Express Edition)创建安装程序
http://www.jrsoftware.org/isinfo.php [



and save that path in one of your .inf file or something.
For the case someone installed your game and runs the update immediately after installation, you''ve to sure it''s started before updated once, but I think that''s ok for users, worst case is to write some HelperProgram which executes after installation.

Be also careful with trying to delete and copy files to the ProgramFiles-Dir (both Program Files and Program Files(x86)) because of read-only permission.

For the case your software grows n'' grows you will come to a point where it will be wasteful to write an own updater.
There are some open source automatic updater available, like:
http://autoupdater.codeplex.com/[^]

Create Setup with i.e (or with visual studio setup project, but not available with express edition)
http://www.jrsoftware.org/isinfo.php[^]

Updated: It''s able to read the target directory from game link lnk, maybe this works for you. Is something registred in Windows Registry? Maybe another way to reach your goal ;)

Regards


这篇关于C#如何使用浏览路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆