Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made a launcher for my game server. (World of Warcraft)
I want to get the installpath of the game, browsed by the user.
I'm using this code to browse, and get the installpath, then set some other strings from the installpath string, then just strore in my registry key.

using System;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Win32;
using System.IO;
using System.Net.NetworkInformation;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.Net;
using System.Linq;
using System.Net.Sockets;
using System.Collections.Generic;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string InstallPath, WoWExe, PatchPath;
        private void Form1_Load(object sender, EventArgs e)
        {

            RegistryKey LocalMachineKey_Existence;
            MessageBox.Show("Browse your install location.", "Select Wow.exe");
            OpenFileDialog BrowseInstallPath = new OpenFileDialog();
            BrowseInstallPath.Filter = "wow.exe|*.exe";
            if (BrowseInstallPath.ShowDialog() == DialogResult.OK)
            {
                InstallPath = System.IO.Path.GetDirectoryName(BrowseInstallPath.FileName);
                WoWExe = InstallPath + "\\wow.exe";
                PatchPath = InstallPath + "\\Data\\";

                LocalMachineKey_Existence = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\ExistenceWoW");
                LocalMachineKey_Existence.SetValue("InstallPathLocation", InstallPath);
                LocalMachineKey_Existence.SetValue("PatchPathLocation", PatchPath);
                LocalMachineKey_Existence.SetValue("WoWExeLocation", WoWExe);
            }
        }
    }
}


The problem is:
On some computer, it doesnt stores like it should be. For example, your wow.exe is in C:\ASD\wow.exe, your select it with the browse windows, then the program should store it in the Existence registry key as C:\ASD\Data\ but it stores like this:
C:\ASDData , so it forgots a backslash :S

Look at this picture:

http://img21.imageshack.us/img21/2829/regedita.jpg

My program works cool on my PC, and on my friends pc, but on some pc this "bug" comes out :S
I have windows 7, with .NEt 3.5
Please help me.
Posted

Rather than using string appending, you should use Path.Combine to create directory structures. This way, you don't have to worry about the presence of \\. Here's what I would do for your PatchPath.
PatchPath = Path.Combine(InstallPath, "Data");
 
Share this answer
 
I'm going to test it, it has no change on my computer, maybe it will work now on my friend's computer. It's still weird :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900