source: AE/RequestHelp/src/main.c@ 1022

Last change on this file since 1022 was 1005, checked in by alloc, 10 years ago

RequestHelp initial commit

File size: 2.9 KB
RevLine 
[1005]1#include <stdio.h>
2#include <stdint.h>
3#include <stdbool.h>
4#include <unistd.h>
5#include <dirent.h>
6
7#include "quickmail.h"
8#include "mailFromGui.h"
9
10#define TO "ae-support@oni2.net"
11#define SMTPSERVER "mail.illy.bz"
12#define SUBJECT "AE support request"
13#define SMTPPORT 25
14#define SMTPUSER NULL
15#define SMTPPASS NULL
16
17static void appendString(char** buffer, unsigned int* bufsize, char* append) {
18 if ((strlen(*buffer) + strlen(append) + 2) >= *bufsize) {
19 unsigned int addon = (strlen(append) > 500 ? strlen(append)+500 : 500);
20 *bufsize += addon;
21
22 char* temp = malloc(*bufsize);
23
24 strcpy(temp, *buffer);
25
26 free(*buffer);
27 *buffer = temp;
28 }
29 strcat(*buffer, append);
30}
31
32static char* buildDirectoryListing(char* path, int level) {
33 unsigned int bufsize = 500;
34 char* strbuf = malloc(bufsize);
35 strbuf[0] = 0;
36
37 if (level >= 4)
38 return strbuf;
39
40 struct dirent *dp;
41 DIR *dfd = opendir(path);
42 if(dfd != NULL) {
43 while((dp = readdir(dfd)) != NULL) {
44 if (strcmp(".", dp->d_name) != 0 && strcmp("..", dp->d_name) != 0) {
45 char* name = malloc(strlen(path) + strlen(dp->d_name) + 2);
46 sprintf(name, "%s/%s", path, dp->d_name);
47
48 appendString(&strbuf, &bufsize, name);
49 strcat(strbuf, "\n");
50
51 //printf("%2d: %s\n", level, name);
52
53 char* sub = buildDirectoryListing(name, level+1);
54 appendString(&strbuf, &bufsize, sub);
55 }
56 }
57 closedir(dfd);
58 }
59 return strbuf;
60}
61
62static void sendMail() {
63 char message[500] = "";
64
65 quickmail_initialize();
66 quickmail mailobj = quickmail_create(emailFrom, SUBJECT);
67 quickmail_add_to(mailobj, TO);
68 if (isCCSelected) {
69 quickmail_add_cc(mailobj, emailFrom);
70 }
71
72 if (access("AEInstaller/updater_output.log", F_OK) != 0) {
73 strcat(message, "updater_output.log does not exist!\n");
74 }
75 if (access("AEInstaller/AEI-ProxySettings.xml", F_OK) != 0) {
76 strcat(message, "AEI-ProxySettings.xml does not exist!\n");
77 }
78
79
80 quickmail_set_body(mailobj, message);
81
82 quickmail_add_attachment_file(mailobj, "AEInstaller/updater_output.log", "text/plain");
83 quickmail_add_attachment_file(mailobj, "AEInstaller/AEI-ProxySettings.xml", "text/xml");
84
85 char* dirList = buildDirectoryListing(".", 0);
86 quickmail_add_attachment_memory(mailobj, "DirListing.txt", "text/plain", dirList, strlen(dirList)+1, 1);
87
88 const char* errmsg;
89 quickmail_set_debug_log(mailobj, stderr);
90 if ((errmsg = quickmail_send(mailobj, SMTPSERVER, SMTPPORT, SMTPUSER, SMTPPASS)) != NULL)
91 fprintf(stderr, "Error sending e-mail: %s\n", errmsg);
92 quickmail_destroy(mailobj);
93}
94
95int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
96{
97 if (access("AEInstaller/", F_OK) != 0 || access("AEInstaller/AEInstaller2Updater.jar", F_OK) != 0) {
98 MessageBox(NULL,
99 "Please put this program in your Oni/AE folder!",
100 "Invalid location",
101 MB_OK | MB_ICONERROR);
102 } else {
103 mailFromGui(hInstance, nShowCmd);
104
105 if (isSendSelected)
106 sendMail();
107 }
108
109 return EXIT_SUCCESS;
110}
111
Note: See TracBrowser for help on using the repository browser.