Atrinik Client 2.5
updater/main.c
Go to the documentation of this file.
00001 /************************************************************************
00002 *            Atrinik, a Multiplayer Online Role Playing Game            *
00003 *                                                                       *
00004 *    Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team    *
00005 *                                                                       *
00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game)     *
00007 * and Crossfire (Multiplayer game for X-windows).                       *
00008 *                                                                       *
00009 * This program is free software; you can redistribute it and/or modify  *
00010 * it under the terms of the GNU General Public License as published by  *
00011 * the Free Software Foundation; either version 2 of the License, or     *
00012 * (at your option) any later version.                                   *
00013 *                                                                       *
00014 * This program is distributed in the hope that it will be useful,       *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017 * GNU General Public License for more details.                          *
00018 *                                                                       *
00019 * You should have received a copy of the GNU General Public License     *
00020 * along with this program; if not, write to the Free Software           *
00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             *
00022 *                                                                       *
00023 * The author can be reached at admin@atrinik.org                        *
00024 ************************************************************************/
00025 
00032 #include <stdio.h>
00033 #include <windows.h>
00034 #include <windowsx.h>
00035 #include <mmsystem.h>
00036 #include <direct.h>
00037 #include <shellapi.h>
00038 
00039 #define HUGE_BUF 4096 * 12
00040 
00041 int main(int argc, char *argv[])
00042 {
00043     char params[HUGE_BUF], path[HUGE_BUF], wdir[HUGE_BUF];
00044     int i;
00045 
00046     params[0] = '\0';
00047 
00048     /* Construct the command parameters from arguments. */
00049     for (i = 1; i < argc; i++)
00050     {
00051         strncat(params, argv[i], sizeof(params) - strlen(params) - 1);
00052     }
00053 
00054     /* Check if we have upgrades to apply. */
00055     snprintf(path, sizeof(path), "%s/.atrinik/temp", getenv("APPDATA"));
00056 
00057     if (access(path, R_OK) == 0)
00058     {
00059         SHELLEXECUTEINFO shExecInfo;
00060 
00061         shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
00062         shExecInfo.fMask = 0;
00063         shExecInfo.hwnd = NULL;
00064         shExecInfo.lpVerb = "runas";
00065         shExecInfo.lpFile = "atrinik_updater.bat";
00066         shExecInfo.lpParameters = params;
00067         shExecInfo.lpDirectory = NULL;
00068         shExecInfo.nShow = SW_SHOW;
00069         shExecInfo.hInstApp = NULL;
00070 
00071         ShellExecuteEx(&shExecInfo);
00072     }
00073     /* No updates, execute the client. */
00074     else
00075     {
00076         snprintf(path, sizeof(path), "%s\\atrinik.exe", getcwd(wdir, sizeof(wdir) - 1));
00077         ShellExecute(NULL, "open", path, params, NULL, SW_SHOWNORMAL);
00078     }
00079 
00080     return 0;
00081 }