File: main.c

package info (click to toggle)
actiona 3.11.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 54,580 kB
  • sloc: cpp: 969,398; xml: 52,881; javascript: 32,914; python: 23,909; sh: 550; ansic: 90; makefile: 9
file content (131 lines) | stat: -rw-r--r-- 3,448 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
    Actiona
    Copyright (C) 2008 Jonathan Mercier-Ganady

    Actiona is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Actiona is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.

    Contact : jmgr@jmgr.info
*/

#define UNICODE
#define _UNICODE

#ifdef _WIN64
#error "This program should be compiled as a 32 bit executable"
#endif

#include <windows.h>
#include <Shellapi.h>

enum
{
    LANG_DEFAULT,
    LANG_FR_FR,

    LANG_COUNT
};

enum
{
    TEXT_TITLE_ERROR,
    TEXT_USAGE,
    TEXT_NO_64BIT,
    TEXT_NOT_FOUND,
    TEXT_GENERIC_ERROR,

    TEXT_COUNT
};

static const wchar_t * const texts[TEXT_COUNT][LANG_COUNT] =
{
    {
        L"Error",
        L"Erreur"
    },
    {
        L"Usage: runner language action program parameters",
        L"" //This doesn't get translated
    },
    {
        L"This SFX script can only be run on a 64 bit operating system.",
        L"Ce script SFX ne peut tre excut que sur un systme d'exploitation 64 bit."
    },
    {
        L"Please install Actiona (actiona.tools) before executing this SFX script.",
        L"Merci d'installer Actiona (actiona.tools) avant d'excuter ce script SFX."
    },
    {
        L"Unable to start SFX execution.",
        L"Impossible d'excuter le script SFX."
    }
};

void showMessageBox(int language, int message)
{
    MessageBox(0, texts[message][language], texts[TEXT_TITLE_ERROR][language], MB_OK | MB_ICONERROR);
}

int wmain(int argc, wchar_t **argv)
{
    const wchar_t *language = 0;
    int languageIndex = LANG_DEFAULT;
    SHELLEXECUTEINFO shellExecuteInfo;

    SecureZeroMemory(&shellExecuteInfo, sizeof(SHELLEXECUTEINFO));

    if(argc != 5)
    {
        showMessageBox(LANG_DEFAULT, TEXT_USAGE);

        return -1;
    }

    language = argv[1];

    if(wcscmp(language, L"fr_FR") == 0)
        languageIndex = LANG_FR_FR;
    // Add other languages here

    shellExecuteInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    shellExecuteInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
    shellExecuteInfo.lpVerb = argv[2];
    shellExecuteInfo.lpFile = argv[3];
    shellExecuteInfo.lpParameters = argv[4];
    shellExecuteInfo.nShow = SW_SHOWDEFAULT;

    if(!ShellExecuteEx(&shellExecuteInfo))
    {
        switch((int)shellExecuteInfo.hInstApp)
        {
        case ERROR_FILE_NOT_FOUND:
        case ERROR_PATH_NOT_FOUND:
            showMessageBox(languageIndex, TEXT_NOT_FOUND);
            return -1;

        case ERROR_BAD_FORMAT:
        case ERROR_ACCESS_DENIED:
            showMessageBox(languageIndex, TEXT_NO_64BIT);
            return -1;

        default:
            showMessageBox(languageIndex, TEXT_GENERIC_ERROR);
            return -1;
        }
    }

    WaitForSingleObject(shellExecuteInfo.hProcess, INFINITE);
    CloseHandle(shellExecuteInfo.hProcess);

    return 0;
}