Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <windows.h>
  2. #include <Psapi.h>
  3. #include "avisynth.h"
  4. #include <iostream>
  5.  
  6. #include <string>
  7. #include <algorithm>
  8. using namespace std;
  9.  
  10. bool hasEnding(std::string const &fullString, std::string const &ending) {
  11.     if (fullString.length() >= ending.length()) {
  12.         return (0 == fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
  13.     }
  14.     else {
  15.         return false;
  16.     }
  17. }
  18.  
  19. AVSValue __cdecl IsAvsPmod(AVSValue args, void* user_data, IScriptEnvironment* env)
  20. {
  21.     string exe = args[0].AsString("");
  22.     int insensitive = args[1].AsBool(1);
  23.     if (exe.empty())
  24.         env->ThrowError("IsAvsPmod: exe is empty!");
  25.     char buf[MAX_PATH];
  26.     if (GetProcessImageFileName(GetCurrentProcess(), buf, MAX_PATH)) {
  27.         std::string name(buf);
  28.         if (!insensitive) {
  29.         transform(name.begin(), name.end(), name.begin(), ::tolower);
  30.         transform(exe.begin(),  exe.end(),  exe.begin(),  ::tolower);
  31.     }
  32.         return hasEnding(name, exe);
  33.     }
  34.     return false;
  35. }
  36.  
  37. const AVS_Linkage *AVS_linkage = 0;
  38.  
  39. extern "C" __declspec(dllexport) const char* __stdcall
  40. AvisynthPluginInit3(IScriptEnvironment* env, const AVS_Linkage* const vectors)
  41. {
  42.     AVS_linkage = vectors;
  43.     env->AddFunction("IsAvsPmod", "[exe]s[insensitive]b", IsAvsPmod, 0);
  44.     return "IsAvsPmod?";
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement