-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
132 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
// MSVC/MinGW Compiller | ||
#if _MSC_VER || WIN32 | ||
#define API_EXPORT __declspec(dllexport) | ||
#define API_IMPORT __declspec(dllimport) | ||
#elif __linux__ || __unix__ | ||
// Linux/Unix GNU Compiller | ||
#if defined(__GNUC__) && __GNUC__ >= 4 | ||
#define __GCCAPI__ __attribute__((visibility("default"))) | ||
#else | ||
#define __GCCAPI__ | ||
#endif | ||
|
||
#define API_EXPORT __GCCAPI__ | ||
#define API_IMPORT __GCCAPI__ | ||
|
||
#endif | ||
|
||
#ifdef TEA_COMPILLING | ||
#define TEA_API API_EXPORT | ||
#else | ||
#define TEA_API API_IMPORT | ||
#endif | ||
|
||
int TEA_API tea_main(int argc, char *argv[]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,8 @@ | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
|
||
#include "tea.h" | ||
|
||
#define USE_ONCE_LAUNCH 0 | ||
|
||
#if USE_ONCE_LAUNCH | ||
#include <semaphore.h> | ||
#define TSEM_KNAME "dragon_tea_lock" | ||
#endif | ||
#include "tea_main.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
setlocale(LC_ALL, ""); | ||
|
||
bindtextdomain(DRAGON_TEA_TEXTDOMAIN, DRAGON_TEA_LOCALE_DIR); | ||
textdomain(DRAGON_TEA_TEXTDOMAIN); | ||
|
||
// Check runned on Root | ||
#ifdef TEA_OS_LINUX | ||
if(getuid() == 0) | ||
{ | ||
printf(_("The program is running as root. These privileges can harm the system, please be aware of this. Closing.")); | ||
return EXIT_FAILURE; | ||
} | ||
#endif | ||
|
||
// GUI Init | ||
gtk_init(&argc, &argv); | ||
|
||
#if USE_ONCE_LAUNCH | ||
// Check is only one copy runs | ||
sem_t *sem; | ||
|
||
sem = sem_open(TSEM_KNAME, O_CREAT | O_EXCL, 0644, 1); | ||
if(sem == SEM_FAILED) | ||
{ | ||
ui_error("Program already launched."); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
if(sem_wait(sem) == -1) | ||
{ | ||
perror("sem_wait"); | ||
return EXIT_FAILURE; | ||
} | ||
#endif | ||
|
||
// Run Dragon Tea Messenger | ||
tea_init(); | ||
|
||
// Window Looping | ||
gtk_main(); | ||
|
||
// Free Unused resources DTM | ||
tea_free(); | ||
|
||
#if USE_ONCE_LAUNCH | ||
// Close launch | ||
if(sem_post(sem) == -1) | ||
{ | ||
perror("sem_post"); | ||
return EXIT_FAILURE; | ||
} | ||
if(sem_close(sem) == -1) | ||
{ | ||
perror("sem_close"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
if(sem_unlink(TSEM_KNAME) == -1) | ||
{ | ||
perror("sem_unlink"); | ||
return EXIT_FAILURE; | ||
} | ||
#endif | ||
|
||
return EXIT_SUCCESS; | ||
return tea_main(argc, argv); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include <fcntl.h> | ||
|
||
#include "tea_main.h" | ||
|
||
#include "tea.h" | ||
|
||
#define USE_ONCE_LAUNCH 0 | ||
|
||
#if USE_ONCE_LAUNCH | ||
#include <semaphore.h> | ||
#define TSEM_KNAME "dragon_tea_lock" | ||
#endif | ||
|
||
int TEA_API tea_main(int argc, char *argv[]) | ||
{ | ||
setlocale(LC_ALL, ""); | ||
|
||
bindtextdomain(DRAGON_TEA_TEXTDOMAIN, DRAGON_TEA_LOCALE_DIR); | ||
textdomain(DRAGON_TEA_TEXTDOMAIN); | ||
|
||
// Check runned on Root | ||
#ifdef TEA_OS_LINUX | ||
if(getuid() == 0) | ||
{ | ||
printf(_("The program is running as root. These privileges can harm the system, please be aware of this. Closing.")); | ||
return EXIT_FAILURE; | ||
} | ||
#endif | ||
|
||
// GUI Init | ||
gtk_init(&argc, &argv); | ||
|
||
#if USE_ONCE_LAUNCH | ||
// Check is only one copy runs | ||
sem_t *sem; | ||
|
||
sem = sem_open(TSEM_KNAME, O_CREAT | O_EXCL, 0644, 1); | ||
if(sem == SEM_FAILED) | ||
{ | ||
ui_error("Program already launched."); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
if(sem_wait(sem) == -1) | ||
{ | ||
perror("sem_wait"); | ||
return EXIT_FAILURE; | ||
} | ||
#endif | ||
|
||
// Run Dragon Tea Messenger | ||
tea_init(); | ||
|
||
// Window Looping | ||
gtk_main(); | ||
|
||
// Free Unused resources DTM | ||
tea_free(); | ||
|
||
#if USE_ONCE_LAUNCH | ||
// Close launch | ||
if(sem_post(sem) == -1) | ||
{ | ||
perror("sem_post"); | ||
return EXIT_FAILURE; | ||
} | ||
if(sem_close(sem) == -1) | ||
{ | ||
perror("sem_close"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
if(sem_unlink(TSEM_KNAME) == -1) | ||
{ | ||
perror("sem_unlink"); | ||
return EXIT_FAILURE; | ||
} | ||
#endif | ||
|
||
return EXIT_SUCCESS; | ||
} |