Raised This Month: $140 Target: $400
 35% 

OpenFile


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gubka
Veteran Member
Join Date: Jan 2012
Location: Dublin
Old 08-12-2018 , 23:33   OpenFile
Reply With Quote #1

Hello, anyone can help me to figure out the problem with creating the files using sm function, i dont know why it dont want create files in CS:GO and also create directories with wrong permissions on Linux

I am getting correct path addons/sourcemod/addons/sourcemod/zombieplague/precache/materials/zombie_bomb.txt

PHP Code:
// Gets precache folder path
    
static char sPath[PLATFORM_MAX_PATH];
    
bool bExists ConfigGetCvarFolderPath(CVAR_CONFIG_PATH_PRECACHEsPath"materials"sModel);

    
// Open the file
    
PrintToServer(sPath);
    
///BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, sPath); I also tryed to use that before openFile
    
File hBase OpenFile(sPath"at+"); 
hBase always INVALID_HANDLE, i tryed all modes, a, a+, at+, w, and no changes

PHP Code:
stock bool ConfigGetCvarFolderPath(const CvarsList iConVarchar[] sPath, const char[] sFolder, const char[] sFile)
{
    
// Gets cvar path
    
static char sFolderPath[PLATFORM_MAX_PATH];
    
gCvarList[iConVar].GetString(sFolderPathsizeof(sFolderPath));

    
// Build full path in return string
    
BuildPath(Path_SMsPathPLATFORM_MAX_PATHsFolderPath);

    
// If folder doesn't exist, then create it
    
if(!DirExists(sPath))
    {
        
// Create it
        
CreateDirectory(sPath741);
    }
    
    
// Build full path in return string
    
BuildPath(Path_SMsPathPLATFORM_MAX_PATH"%s/%s"sFolderPathsFolder);
    
    
// If folder doesn't exist, then create it
    
if(!DirExists(sPath))
    {
        
// Create it
        
CreateDirectory(sPath741);
    }

    
// Finds the first occurrence of a character in a string
    
int iFile FindCharInString(sFile'/'true); 
    if(
iFile == -1iFile FindCharInString(sFile'\\'true); /// Bugfix for windows separator
    
     // Validate no file
    
if(iFile == -1)
    {
        return 
false;
    } 
    
    
// Finds the first occurrence of a character in a string
    
int iFormat FindCharInString(sFile'.'true);
    
    
// Validate no format
    
if(iFormat == -1)
    {
        return 
false;
    }
    
    
// Extract file name
    
static char sName[PLATFORM_MAX_PATH];
    
StrExtract(sNamesFileiFileiFormat);
    
    
// Format full path to file
    
BuildPath(Path_SMsPathPLATFORM_MAX_PATH"%s%s.txt"sPathsName);

    
// If file is exist, then return true
    
return FileExists(sPath);

Is it possible to create txt files in folder of models/materials for example instead ????????
__________________

Last edited by gubka; 08-13-2018 at 00:00.
gubka is offline
Send a message via ICQ to gubka Send a message via Skype™ to gubka
SHUFEN.jp
Senior Member
Join Date: Jun 2014
Location: Japan, Tokyo
Old 08-13-2018 , 06:54   Re: OpenFile
Reply With Quote #2

Code:
bool FileOperation() {
	// csgo/addons/sourcemod/configs/test.txt
	char sSourcePath[PLATFORM_MAX_PATH];
	BuildPath(Path_SM, sSourcePath, PLATFORM_MAX_PATH, "configs/test.txt");

	// csgo/materials/models/test.vmt
	char sTargetPath[PLATFORM_MAX_PATH];
	FormatEx(sTargetPath, sizeof(sTargetPath), "materials/models/test.vmt");

	Handle hBaseFile = OpenFile(sSourcePath, "rb");
	if (hBaseFile == INVALID_HANDLE) {
		PrintToServer("  -- Can't open base \"%s\" file!", sSourcePath);
		return false;
	}

	if (FileExists(sTargetPath)) {
		PrintToServer("  -- Already exists \"%s\" file.", sTargetPath);
		delete hBaseFile;
		return false;
	}

	Handle hCopyTarget = OpenFile(sTargetPath, "wb");
	if (hCopyTarget == INVALID_HANDLE){
		PrintToServer("  -- Can't create target \"%s\" file!", sTargetPath);
		delete hBaseFile;
		return false;
	}

	int iBuffer[32];
	int iReadCache;

	while (!IsEndOfFile(hBaseFile)){
		iReadCache = ReadFile(hBaseFile, iBuffer, 32, 1);
		WriteFile(hCopyTarget, iBuffer, iReadCache, 1);
	}

	delete hCopyTarget;
	delete hBaseFile;
	PrintToServer("  -- Successful to Create File: Path is \"%s\" file.", sTargetPath);
	return true;
}
This should work at least. But idk if directory has wrong permission.
__________________

SHUFEN.jp is offline
Send a message via Skype™ to SHUFEN.jp
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 08-13-2018 , 13:44   Re: OpenFile
Reply With Quote #3

Quote:
Originally Posted by gubka View Post
Hello, anyone can help me to figure out the problem with creating the files using sm function, i dont know why it dont want create files in CS:GO and also create directories with wrong permissions on Linux

I am getting correct path addons/sourcemod/addons/sourcemod/zombieplague/precache/materials/zombie_bomb.txt
That path looks pretty incorrect to me. You're basically BuildPathing the same thing twice.
Fyren is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:06.


Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Theme made by Freecode