Cは私の大きな力ではありませんでしたが、試してみることにしました。以下は私のコードですが、実行するとセグメンテーション エラー (コア ダンプ) が発生します。
基本的に私が望むのは、フォルダーが空であるかどうか(mtpデバイスがマウントされているかどうか)を確認し、空の場合はmountコマンドを実行し、そうでない場合は他のコマンドを実行することです。
#include <sys/types.h>
#include <dirent.h>
#include <libgen.h>
#include <libnotify/notify.h>
#include <stdio.h>
#include <unistd.h>
void main ()
{
int n = 0;
struct dirent *d;
const char *dir_path="~/Nexus";
DIR *dir = opendir(dir_path);
while ((d = readdir(dir)) != NULL) {
if(++n > 2)
break;
}
closedir(dir);
if (n <= 2) //Directory Empty
{
notify_init ("Galaxy Nexus mounter");
NotifyNotification * Mount = notify_notification_new ("Galaxy Nexus", "Mounted at ~/Nexus", "/home/tristan202/bin/test/android_on.png");
system("jmtpfs ~/Nexus");
notify_notification_show (Mount, NULL);
}
else
{
notify_init ("Galaxy Nexus mounter");
NotifyNotification * uMount = notify_notification_new ("Galaxy Nexus", "Unmounted", "/home/tristan202/bin/test/android_off.png");
system("fusermount -u ~/Nexus");
notify_notification_show (uMount, NULL);
}
}
どんな提案でも大歓迎です。
編集
#include <sys/types.h>
#include <dirent.h>
#include <libgen.h>
#include <libnotify/notify.h>
#include <stdio.h>
#include <unistd.h>
int main ()
{
int n = 0;
struct dirent *d;
const char *dir_path="/home/tristan202/Nexus";
DIR *dir = opendir(dir_path);
while ((d = readdir(dir)) != NULL) {
if(++n > 2)
break;
}
closedir(dir);
if (n <= 2) //Directory Empty
{
notify_init ("Galaxy Nexus mounter");
NotifyNotification * Mount = notify_notification_new ("Galaxy Nexus", "Mounted at ~/Nexus", "/home/tristan202/bin/test/android_on.png");
system("jmtpfs ~/Nexus");
notify_notification_show (Mount, NULL);
}
else
{
notify_init ("Galaxy Nexus mounter");
NotifyNotification * uMount = notify_notification_new ("Galaxy Nexus", "Unmounted", "/home/tristan202/bin/test/android_off.png");
system("fusermount -u ~/Nexus");
notify_notification_show (uMount, NULL);
}
}