示例#1
0
  void MultiresImagePlugin::SaveConfig(YAML::Emitter& emitter, const std::string& path)
  {
    boost::filesystem::path abs_path(ui_.path->text().toStdString());
    boost::filesystem::path base_path(path);
    boost::filesystem::path rel_path = MakePathRelative(abs_path, base_path);

    emitter << YAML::Key << "path" << YAML::Value << rel_path.string();
  }
示例#2
0
INT_PTR ProtectAvatar(WPARAM hContact, LPARAM lParam)
{
	BYTE was_locked = db_get_b(hContact, "ContactPhoto", "Locked", 0);

	if (fei == NULL || was_locked == (BYTE)lParam)      // no need for redundant lockings...
		return 0;

	if (hContact) {
		if (!was_locked)
			MakePathRelative(hContact);
		db_set_b(hContact, "ContactPhoto", "Locked", lParam ? 1 : 0);
		if (lParam == 0)
			MakePathRelative(hContact);
		ChangeAvatar(hContact, true);
	}
	return 0;
}
示例#3
0
static INT_PTR avSetAvatar(MCONTACT hContact, TCHAR *tszPath)
{
	TCHAR FileName[MAX_PATH];
	TCHAR *szFinalName;
	BYTE locking_request;

	if (hContact == NULL || fei == NULL)
		return 0;

	int is_locked = db_get_b(hContact, "ContactPhoto", "Locked", 0);

	if (tszPath == NULL) {
		OPENFILENAME ofn = { 0 };
		TCHAR filter[256];

		filter[0] = '\0';
		CallService(MS_UTILS_GETBITMAPFILTERSTRINGST, SIZEOF(filter), (LPARAM)filter);

		ofn.lStructSize = sizeof(ofn);
		ofn.hwndOwner = 0;
		ofn.lpstrFile = FileName;
		ofn.lpstrFilter = filter;
		ofn.nMaxFile = MAX_PATH;
		ofn.nMaxFileTitle = MAX_PATH;
		ofn.Flags = OFN_FILEMUSTEXIST | OFN_ENABLETEMPLATE | OFN_EXPLORER | OFN_ENABLESIZING | OFN_ENABLEHOOK;
		ofn.lpstrInitialDir = _T(".");
		*FileName = '\0';
		ofn.lpstrDefExt = _T("");
		ofn.hInstance = g_hInst;
		ofn.lpTemplateName = MAKEINTRESOURCE(IDD_OPENSUBCLASS);
		ofn.lpfnHook = OpenFileSubclass;
		locking_request = is_locked;
		ofn.lCustData = (LPARAM)&locking_request;
		if (!GetOpenFileName(&ofn))
			return 0;

		szFinalName = FileName;
		is_locked = locking_request ? 1 : is_locked;
	}
	else szFinalName = tszPath;

	// filename is now set, check it and perform all needed action
	if (_taccess(szFinalName, 4) == -1)
		return 0;

	// file exists...
	TCHAR szBackupName[MAX_PATH];
	PathToRelativeT(szFinalName, szBackupName, g_szDataPath);
	db_set_ts(hContact, "ContactPhoto", "Backup", szBackupName);

	db_set_b(hContact, "ContactPhoto", "Locked", is_locked);
	db_set_ts(hContact, "ContactPhoto", "File", szFinalName);
	MakePathRelative(hContact, szFinalName);

	// Fix cache
	ChangeAvatar(hContact, true);
	return 0;
}
示例#4
0
void ProcessAvatarInfo(MCONTACT hContact, int type, PROTO_AVATAR_INFORMATIONT *pai, const char *szProto)
{
	QueueRemove(hContact);

	if (type == GAIR_SUCCESS) {
		if (pai == NULL)
			return;

		// Fix settings in DB
		db_unset(hContact, "ContactPhoto", "NeedUpdate");
		db_unset(hContact, "ContactPhoto", "RFile");
		if (!db_get_b(hContact, "ContactPhoto", "Locked", 0))
			db_unset(hContact, "ContactPhoto", "Backup");
		db_set_ts(hContact, "ContactPhoto", "File", pai->filename);
		db_set_w(hContact, "ContactPhoto", "Format", pai->format);

		if (pai->format == PA_FORMAT_PNG || pai->format == PA_FORMAT_JPEG
			 || pai->format == PA_FORMAT_ICON || pai->format == PA_FORMAT_BMP
			 || pai->format == PA_FORMAT_GIF) {
			// We can load it!
			MakePathRelative(hContact, pai->filename);
			ChangeAvatar(hContact, TRUE, TRUE, pai->format);
		}
		else // As we can't load it, notify but don't load
			ChangeAvatar(hContact, FALSE, TRUE, pai->format);
	}
	else if (type == GAIR_NOAVATAR) {
		db_unset(hContact, "ContactPhoto", "NeedUpdate");

		if (db_get_b(NULL, AVS_MODULE, "RemoveAvatarWhenContactRemoves", 1)) {
			// Delete settings
			db_unset(hContact, "ContactPhoto", "RFile");
			if (!db_get_b(hContact, "ContactPhoto", "Locked", 0))
				db_unset(hContact, "ContactPhoto", "Backup");
			db_unset(hContact, "ContactPhoto", "File");
			db_unset(hContact, "ContactPhoto", "Format");

			// Fix cache
			ChangeAvatar(hContact, FALSE, TRUE, 0);
		}
	}
	else if (type == GAIR_FAILED) {
		int wait = Proto_GetDelayAfterFail(szProto);
		if (wait > 0) {
			// Reschedule to request after needed time (and avoid requests before that)
			mir_cslock lock(cs);
			QueueRemove(hContact);
			QueueAdd(hContact, wait);
		}
	}
}
示例#5
0
void SolveSpace::ReloadAllImported(void) {
    allConsistent = false;

    int i;
    for(i = 0; i < SK.group.n; i++) {
        Group *g = &(SK.group.elem[i]);
        if(g->type != Group::IMPORTED) continue;

        g->impEntity.Clear();
        g->impMesh.Clear();
        g->impShell.Clear();

        FILE *test = fopen(g->impFile, "rb");
        if(test) {
            fclose(test); // okay, exists
        } else {
            // It doesn't exist. Perhaps the entire tree has moved, and we
            // can use the relative filename to get us back.
            if(SS.saveFile[0]) {
                char fromRel[MAX_PATH];
                strcpy(fromRel, g->impFileRel);
                MakePathAbsolute(SS.saveFile, fromRel);
                test = fopen(fromRel, "rb");
                if(test) {
                    fclose(test);
                    // It worked, this is our new absolute path
                    strcpy(g->impFile, fromRel);
                }
            }
        }

        if(LoadEntitiesFromFile(g->impFile,
                        &(g->impEntity), &(g->impMesh), &(g->impShell)))
        {
            if(SS.saveFile[0]) {
                // Record the imported file's name relative to our filename;
                // if the entire tree moves, then everything will still work
                strcpy(g->impFileRel, g->impFile);
                MakePathRelative(SS.saveFile, g->impFileRel);
            } else {
                // We're not yet saved, so can't make it absolute
                strcpy(g->impFileRel, g->impFile);
            }
        } else {
            Error("Failed to load imported file '%s'", g->impFile);
        }
    }
}
示例#6
0
 boost::filesystem::path MultiresImagePlugin::MakePathRelative(boost::filesystem::path path, boost::filesystem::path base)
 {
   // Borrowed from: https://svn.boost.org/trac/boost/ticket/1976#comment:2
   if (path.has_root_path())
   {
     if (path.root_path() != base.root_path())
     {
       return path;
     }
     else
     {
       return MakePathRelative(path.relative_path(), base.relative_path());
     }
   }
   else
   {
     if (base.has_root_path())
     {
       ROS_WARN("Cannot uncomplete a path relative path from a rooted base.");
       return path;
     }
     else
     {
       typedef boost::filesystem::path::const_iterator path_iterator;
       path_iterator path_it = path.begin();
       path_iterator base_it = base.begin();
       while (path_it != path.end() && base_it != base.end())
       {
         if (*path_it != *base_it)
           break;
         ++path_it;
         ++base_it;
       }
       boost::filesystem::path result;
       for (; base_it != base.end(); ++base_it)
       {
         result /= "..";
       }
       for (; path_it != path.end(); ++path_it)
       {
         result /= *path_it;
       }
       return result;
     }
   }
 }
示例#7
0
static INT_PTR avSetAvatar(HANDLE hContact, TCHAR *tszPath)
{
	BYTE is_locked = 0;
	TCHAR FileName[MAX_PATH], szBackupName[MAX_PATH];
	TCHAR *szFinalName = NULL;
	HANDLE hFile = 0;
	BYTE locking_request;

	if (hContact == NULL || fei == NULL)
		return 0;

	is_locked = db_get_b(hContact, "ContactPhoto", "Locked", 0);

	if ( tszPath == NULL ) {
		OPENFILENAME ofn = {0};
		TCHAR filter[256];

		filter[0] = '\0';
		CallService(MS_UTILS_GETBITMAPFILTERSTRINGST, SIZEOF(filter), ( LPARAM )filter);

		ofn.lStructSize = sizeof(ofn);
		ofn.hwndOwner = 0;
		ofn.lpstrFile = FileName;
		ofn.lpstrFilter = filter;
		ofn.nMaxFile = MAX_PATH;
		ofn.nMaxFileTitle = MAX_PATH;
		ofn.Flags = OFN_FILEMUSTEXIST | OFN_ENABLETEMPLATE | OFN_EXPLORER | OFN_ENABLESIZING | OFN_ENABLEHOOK;
		ofn.lpstrInitialDir = _T(".");
		*FileName = '\0';
		ofn.lpstrDefExt = _T("");
		ofn.hInstance = g_hInst;
		ofn.lpTemplateName = MAKEINTRESOURCE(IDD_OPENSUBCLASS);
		ofn.lpfnHook = OpenFileSubclass;
		locking_request = is_locked;
		ofn.lCustData = (LPARAM)&locking_request;
		if (GetOpenFileName(&ofn)) {
			szFinalName = FileName;
			is_locked = locking_request ? 1 : is_locked;
		}
		else
			return 0;
	}
	else
		szFinalName = tszPath;

	/*
	* filename is now set, check it and perform all needed action
	*/

	if ((hFile = CreateFile(szFinalName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)
		return 0;

	// file exists...

	CloseHandle(hFile);

	AVS_pathToRelative(szFinalName, szBackupName);
	db_set_ts(hContact, "ContactPhoto", "Backup", szBackupName);

	db_set_b(hContact, "ContactPhoto", "Locked", is_locked);
	db_set_ts(hContact, "ContactPhoto", "File", szFinalName);
	MakePathRelative(hContact, szFinalName);
	// Fix cache
	ChangeAvatar(hContact, TRUE);

	return 0;
}
示例#8
0
void MakePathRelative(MCONTACT hContact)
{
	ptrT tszPath(db_get_tsa(hContact, "ContactPhoto", "File"));
	if (tszPath)
		MakePathRelative(hContact, tszPath);
}
示例#9
0
 /// \brief
 ///   Makes szDestPath relative to szStartPath. The result might start with "..\"
 ///   
 /// \param szStartPath
 /// 	Starting point of your relative path.
 ///   
 /// \param szDestPath
 ///   The resulting string is the relative path between szDestPath and szStartPath.
 ///   
 /// \return
 /// 	A VString containing the relative path.
 ///   
 /// \note
 ///   Internally creates a temp buffer on the stack. Do not use it extensively for time critical processes.  
 VBASE_IMPEXP static inline VString MakePathRelative(const char* szStartPath, const char *szDestPath)
 {
   char szBuffer[FS_MAX_PATH];
   MakePathRelative(szBuffer, szStartPath, szDestPath);
   return VString(szBuffer);
 }
示例#10
0
bool SolveSpaceUI::ReloadAllImported(bool canCancel)
{
    std::map<std::string, std::string> importMap;
    allConsistent = false;

    int i;
    for(i = 0; i < SK.group.n; i++) {
        Group *g = &(SK.group.elem[i]);
        if(g->type != Group::IMPORTED) continue;

        if(isalpha(g->impFile[0]) && g->impFile[1] == ':') {
            // Make sure that g->impFileRel always contains a relative path
            // in an UNIX format, even after we load an old file which had
            // the path in Windows format
            PathSepNormalize(g->impFileRel);
        }

        g->impEntity.Clear();
        g->impMesh.Clear();
        g->impShell.Clear();

        if(importMap.count(g->impFile)) {
            std::string newPath = importMap[g->impFile];
            if(!newPath.empty())
                g->impFile = newPath;
        }

        FILE *test = ssfopen(g->impFile, "rb");
        if(test) {
            fclose(test); // okay, exists
        } else {
            // It doesn't exist. Perhaps the entire tree has moved, and we
            // can use the relative filename to get us back.
            if(!SS.saveFile.empty()) {
                std::string rel = PathSepUNIXToPlatform(g->impFileRel);
                std::string fromRel = MakePathAbsolute(SS.saveFile, rel);
                test = ssfopen(fromRel, "rb");
                if(test) {
                    fclose(test);
                    // It worked, this is our new absolute path
                    g->impFile = fromRel;
                }
            }
        }

try_load_file:
        if(LoadEntitiesFromFile(g->impFile, &(g->impEntity), &(g->impMesh), &(g->impShell)))
        {
            if(!SS.saveFile.empty()) {
                // Record the imported file's name relative to our filename;
                // if the entire tree moves, then everything will still work
                std::string rel = MakePathRelative(SS.saveFile, g->impFile);
                g->impFileRel = PathSepPlatformToUNIX(rel);
            } else {
                // We're not yet saved, so can't make it absolute.
                // This will only be used for display purposes, as SS.saveFile
                // is always nonempty when we are actually writing anything.
                g->impFileRel = g->impFile;
            }
        } else if(!importMap.count(g->impFile)) {
            switch(LocateImportedFileYesNoCancel(g->impFileRel, canCancel)) {
            case DIALOG_YES: {
                std::string oldImpFile = g->impFile;
                if(!GetOpenFile(g->impFile, "", SLVS_PATTERN)) {
                    if(canCancel)
                        return false;
                    break;
                } else {
                    importMap[oldImpFile] = g->impFile;
                    goto try_load_file;
                }
            }

            case DIALOG_NO:
                importMap[g->impFile] = "";
                /* Geometry will be pruned by GenerateAll(). */
                break;

            case DIALOG_CANCEL:
                return false;
            }
        } else {
            // User was already asked to and refused to locate a missing
            // imported file.
        }
    }

    return true;
}